Classification in Objective-C
This article shows you the categories in Objective-C, which are concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Animal.h
# import
@ interface Animal: NSObject
-(void) eat: (NSString *) food
@ end
Animal.m
# import "Animal.h"
@ implementation Animal
/ * *
Eat
/
-(void) eat: (NSString) food {
NSLog (@ "I like eat% @", food)
}
@ end
Testing in the main entry
# import
# import "Animal.h"
Int main (int argc, const char argv []) {
@ autoreleasepool {
Animal dog = [[Animal alloc] init]
NSString * food = @ "Bone"
[dog eat:food]
}
Return 0
}
Results:
First, name and classify AnimalPart
H:
# import
# import "Animal.h"
@ interface Animal (AnimalPart)
-(void) call: (NSString *) sound;@end