1. Memory Management
? ? ? ? Concept, when alloc an object, which constitutes the object itself +retaincount, this retaincount is the object counter. The only basis to judge whether an object should be recycled (there is an exception: when the object value is nil, the reference count is 0, but the space is not reclaimed) is the counter is 0, if not 0 exists. The dealloc is sent to the system before the object is destroyed, of course you can override this function. Dealloc cannot be called directly, and if the comment is recycled the object is used again to report the wild Pointer (Zombie). Zombie monitoring can be turned on in the diagnostics.
? ? ? ? Objective-c?? Three memory management options: Mannulreference counting (MRC, manual management, we are responsible for using reference counting to manage memory, such as manually retain, release, and in the development of projects prior to iOS4.1. Autorelease, and later versions can use ARC to allow the system to manage its own memory. ) Automatic reference counting (ARC, auto reference count, iOS4.1) garbage collection (garbage collection). iOS does not support garbage collection; Arc as Apple new?? Technology, Apple recommends that developers use ARC technology to manage memory;
? ? ? ? To call retain,release manually, you must turn off arc. Can be set in build setting.
? ? ? ??
? ? ? ? It is highly recommended that you do not need to manually host resource counts and releases, and then skip. ARC is not a garbage collection, it is a compiler attribute that is not a runtime attribute. ARC Determines whether the rule is recycled, and at least one strong pointer to the object does not perform the collection.
?
2.Category and C#exten class, all without changing the current class, the new class expands the current class's API.
3. The Magic Block,apple recommended data type. Use a wide range of scenarios to save a piece of code at the right time to call.
[Email protected] protocol, which is consistent with the abstract of C #, in fact there is nothing to say. There are two keywords @required must implement this method, @optional can choose not to implement, it is well known that the interface can inherit more OC is no exception.
5. The code is so much for the time being, then write it back.
#import <Foundation/Foundation.h>
?
// Declare a protocol that is the interface in C#
@protocol Iprototoltest
?
@required -(void) Showtxt:(nsstring*) str;
@optional -(void) Showtxtnoparams;
?
@end
?
@interface TestClass:nsobject <iprototoltest>
{
? ? @public
? ? int name;
}
-(void) Printname: (nsstring*) name;
?
@end
?
?
@implementation TestClass
?
-(void) Printname: (nsstring *) name
{
? ? NSLog (name);
}
?
-(void) Showtxt: (nsstring *) str
{
? ? NSLog (str);
}
?
@end
?
@interface TestClass (TestCategory)
-(void) SayHello;
@end
@implementation TestClass (TestCategory)
?
-(void) SayHello
{
? ? NSLog (@ "HelloWorld");
}
?
@end
?
?
?
void (^testblockmethod) (int, nsstring*) = ^ (int x, nsstring* y)
{
? ? NSLog (@ "%d +++++%@", x, y);
};
?
int Main (int argc, const Char * argv[]) {
? ? @autoreleasepool {
? ? ? ? testclass *s = [[testclass alloc] init];
? ? ? ? [s SayHello];
?? ? ? ?
? ? ? ? Testblockmethod (1001,@ "Testblock ...");
?? ? ? ?
? ? }
? ? return 0;
}
The advanced stage of OC Learning