objective-c Medium Categary( Category ) It's quite widely used , Its connotation is similar to javascript Medium prototype, Methods that can extend a class .

Here's a basic example , Reference resources oc Programming book :

  • Achieve one categary
#import <Foundation/Foundation.h>
@interface NSString(Util) // stay NSString On the basis of Util Category
-(BOOL)isUrl;
@end
#import "NSString+Util.h"
@implementation NSString(Util)
-(BOOL)isu
{
if([self hasPrefix:@"http"]){
return TRUE;
}else{
return FALSE;
}
} @end
  • Test code
#import <Foundation/Foundation.h>
#import "NSString+Util.h" // Include header files and start using this category int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *test1 = @"http://lcacds";
NSString *test2 = @"fdsfs"; if([test1 isUrl]){ // Judge whether it is a URL link
NSLog(@"%@ is url", test1);
}else{
NSLog(@"%@ not url", test1);
} if([test2 isUrl]){
NSLog(@"%@ is url", test2);
}else{
NSLog(@"%@ not url", test2);
}
}
return ;
}

objective-c( Category ) More articles about

  1. Automake

    Automake It's based on Makefile.am Generate Makefile.in Tools for standard Makefile The goal is 'make all' Build programs, libraries, document ...

  2. 【IOS Development 】Objective - C Advanced object-oriented features - Packaging | Class processing | Category | Expand | agreement | entrust | exception handling | Reflection

    One . Objective-C Objects are handled simply 1. Packaging (1) Brief introduction of packaging NSValue and NSNumber : -- General packaging NSValue : NSValue The package is single short, i ...

  3. Objective C code snippet ( Category )

    @interface NSString (reverse) -(NSString *) reverseString; @end @implementation NSString (reverse) - ...

  4. warren Objective-C Runtime

    http://chun.tips/blog/2014/11/05/bao-gen-wen-di-objective%5Bnil%5Dc-runtime-(2)%5Bnil%5D-object-and- ...

  5. Objective C Class method load and initialize The difference between

    Objective C Class method load and initialize The difference between   In the past two weeks , In order to finish a job , Access to NSObject Two very special class methods in (Class Method). What's special about them , lie in ...

  6. iOS Development —— Summary of the actual combat of the project &amp; Let me show you Objective-C The essence of

    Let me show you Objective-C The essence of 1: Interface and implementation @interface...@end @implementation...@end @class Interface ( The header file ) Implementation file Forward reference notes : By adding ...

  7. iOS Developing the core language Objective C —— Summary of all knowledge points

    This sharing is for those who intend to engage in iOS Development partners and Apple product enthusiasts , Or have engaged in iOS Developers of , Those who want to ascend further . Suppose you are right about iOS There's a lot of interest in development , Be able to discuss with me iOS Development . Learning together , Common progress . Suppose you are a zero base ...

  8. OC in SEL, Category , Inherit , Use of protocol

    1.SEL SEL yes selector Abbreviation ,selector stay OC The role is to define a method variable , Call the method through the method variable . We're in the back UI It's often used in English selector To call the event method . Now I will give two examples to illustrate ...

  9. IOS Miscellaneous pen -12( Category de Skillfully use It's convenient for Frame The operation of )

    In the actual development, many times we are for the control frame Our operation is in a mess . for example : We just want to get view Of width. We can do this :view.frame.size.width Sometimes we want to change view Of wid ...

  10. Oracle Study note 4 SQL command ( Two ):SQL Operating language categories

    SQL It is divided into the following language categories 1. Data definition language (DDL) Create.Alter.Drop 2. Data manipulation language (DML) Insert.Select.Delete.Update 3. Transaction control language (TCL) ...

Random recommendation

  1. js Medium caller and callee attribute

    caller Returns a reference to a function , This function calls the current function . functionName.caller functionName Object is the name of the function being executed . Explain that for functions ,caller Property only when the function executes ...

  2. [Android L]SEAndroid enhance Androd Security background summary and impact

    1  SEAndroid background   Android For the enhancement of operating system security, we always use Linux The kernel provides MAC Mandatory access control Suite SELinux, More in-depth management of permissions , It effectively controls the process's access to resources ...

  3. 2015 In the first 3 Ben ( English No 2 Ben ):Daughter of Deceit

    Title :Daughter of Deceit author : Victoria Holt ( Victoria · Holt ) Number of words :12 ten thousand vocabulary :6000 The first ten thousand words are not repeated :1700 Lansi value :570 Reading time :1 month 12 Japan - ...

  4. The method of sequence (str,list,tuple)

    author :Vamei Source :http://www.cnblogs.com/vamei Welcome to reprint , Please also retain this statement . thank you ! In the quick tutorial , We've learned the most basic sequence (sequence). recall , Sequences contain fixed values ...

  5. Eclipse install SVN Plug in summary

    1. Download the latest Eclipse, My version is 3.7.2 indigo(Eclipse IDE for Java EE Developers) edition     If not, please download and install it here :http://ecli ...

  6. Jumping Cows_ greedy

    Description Farmer John's cows would like to jump over the moon, just like the cows in their favorit ...

  7. Kooboo How to add an association in Details Dynamic pages .

    Kooboo How to add an association in Details Dynamic pages . There are several points : 1. Sub Page Of Parent Page  It must be written in English . If it's in Chinese, the page can't be found 500 error 2.  To be in Page M ...

  8. A Ming linux note

    2015-09-06 Virtual machine network settings .wmv: curl     Get the web page displayed on the command line dhclient     Distribute ip Address ifdown eth0     Close network card eth0 ifup eh0   ...

  9. 2019 year 3 month 29 solstice 30 Japan and Shenzhen are making joint efforts 《 A successful product manager DNA》 The open class was successfully held in Shenzhen

    2019 year 3 month 29 to 30 Japan , At Zhongnan Seaside Hotel, Nanshan District, Shenzhen 10 Building Administration , Held by Shenzhen gongchuangli Enterprise Management Consulting Co., Ltd < A successful product manager DNA> The open class was held successfully , This open class was held by senior lecturer Feng Lao of Shenzhen gongchuangli Consulting Co., Ltd ...

  10. Hello vue.js My essay

    Two way data binding script Only after the component definition location . If you use it , quote js Just fine , Relatively simple . Make a statement vm object ,new Vue({}). An object is passed in this structure , contain el: interface element ,data: data ,meth ...