Objective-CIs the content of this article, mainly to learnObjective-CAttribute features,NSAID utoreleasepoolUnderstanding, Emacs mobile shortcuts +Common Xcode keysFor more information, see.
1. Objective-C attribute features assign, retain, copy, readonly, readwrite)
Assign: Specifies the setter method to use a simple value assignment, which is the default operation. You can use this attribute for scalar types such as int. You can imagine a float. It is not an object, so it cannot be retain or copy.
Retain: specifies that the retain should be called on a later object. The previous value sends a release message. You can imagine an NSString instance, which is an object and you may want to retain it.
Copy: specifies that the object's copy should be used for deep replication). The previous value sends a release message. Basically like retain, but does not increase the reference count, it is to allocate a new memory to place it.
Readonly: only the getter method is generated, but the getter method is not generated. The getter method has no get prefix ).
Readwrite: the default attribute. The getter and setter methods without additional parameters are generated with only one parameter ).
2. Learn more about NSAID utoreleasepool
A set of stored objects. Objects added to the NSAID pool can be automatically released.
The automatic release actually sends a release message to all objects in the pool when the ngutoreleasepool is cleared or destroyed.
The object is not automatically added to the pool. It is added to the current pool only when the object sends an autorelease message. It can be imagined that the pool is in a stack, and the current pool is at the top of the stack. Every time a new pool is created, it is pushed in. When drain or release is used, it will pop up.
If an object is an Autorelease object, but there is no NSAID utoreleasepool, the system will prompt the memory leakage Just Leaking ). In general, as long as an object is not created using the new, alloc, and copy methods, we assume that the reference count of this object is 1 and added to the NSAID utoreleasepool.
The following code prompts a memory leak:
- NSDate *date = [NSDate date];
- NSLog(@"%@",[date description]);
- return 0;
- /*
- objc[3466]: Object 0x1001149c0 of class __NSDate autoreleased
- with no pool in place
- - just leaking - break on objc_autoreleaseNoPool() to debug
- */
- NSDate *date = [NSDate date];
- NSLog(@"%@",[date description]);
- return 0;
- /*
- objc[3466]: Object 0x1001149c0 of class __NSDate autoreleased
- with no pool in place
- - just leaking - break on objc_autoreleaseNoPool() to debug
- */
For drain and release problems, you can find instructions here. In a non-GC environment, the two functions the same. Otherwise, you have no reason to use release. If you send drain to the NSAID utoreleasepool, the GC will be reminded to process objects in the pool.
3. Emacs mobile shortcuts + Xcode shortcuts
Although you do not want to learn how to use Emacs, you can record the xcode shortcut keys in the URL address bar of Xcode, TextEdit, and Safari to make them easier to use on Mac.
- Control-F Forward to the right)
- Control-B moves to the left Backward)
- Control-N down Next) Move a row
- Control-P move a row up Previous)
- Control-K Delete Kill) code after the cursor
- Control-A moves to the beginning of the line with the command + left arrow)
- Control-E move to the end of the row with the command + right arrow)
- Control-T Transpose, swap) symbols on both sides of the cursor
- Control-D Delete) the character on the right of the cursor
- Control-L puts the insert point in the center of the window)
Xcode shortcut:
- Command + [move code block left
- Command +] Right Shift code block
- Tab accept code prompt
- Ese display code prompt
- Control +. Circular browsing code prompt
- Shift + Control +. Reverse browsing code prompt
- Control +/move to the next point in the code prompt
- Command + Control + S create Snapshot
Summary: AboutObjective-CAttribute features,NSAID utoreleasepoolUnderstanding, Emacs mobile shortcuts +Common Xcode keysThe content of this article has been introduced. I hope this article will help you!