- NSObject
NSObject is the root class of most Objective-C class hierarchies.
- NSNumber
- NSAutoReleasePool
- NSString,NSMutableString
Contains unicode characters. i.e.: @"This is Objective-C string";
Whereas C-style strings consist of char characters, NSString objects consist of unichar characters.A unichar character is a multibyte character according to the Unicode standard.This enables you to work with character sets that can contain literally millions of characters.
The NSString class deals with immutable strings.
The NSMutableString class can be used to create string objects whose characters can be
changed.
- NSLog
- NSArray, NSMutableArray
Its elements are offen of one type, but that is not required (can be of different types) - NSDictionary/NSMutableDictionary
Is a connection of key-value pairs - NSSet/NSMutableSet
Is a connection of unique object. - NSData
NSData class provides an easy way to set up a buffer, read the
contents of the file into it, or write the contents of a buffer out to a file.
- File Operation
I) NSFileManager
Manage files and directories
II) NSFileHandle
Handle File I/O
III) Path utils
a) The methods declared in NSPathUtilities.h. In fact, they are defined
in NSString category, such as NSString:pathExtension:,
NSString:pathComponents: etc.
b)
* NSFullUserName
* NSHomeDirectory
* NSHomeDirectoryForUser
* NSOpenStepRootDirectory
* NSSearchPathForDirectoriesInDomains
* NSTemporaryDirectory
* NSUserName
IV) NSProcessInfo
Get/Set Process information, such as arguments, environment, process name, host name, system name, memory etc. - Memory Management: Autorelease Pool
I) Create autorelease pool
NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init];
II) Destroy autorelease pool
[pool drain]
III) Add objects to autorelease pool
Foundation automatically adds arrays, strings, dictionarys, and other
objects to the autorelease pool. If you don't use foundation framework
(such class doesn't inherit from class from foundation framework), you
can call [YourObject autorelease] to add your object to autorelease
pool.
IV) Reference Counting
[AClass alloc] reference count it set to 1,
[AObject retain] increase reference count of AObject by 1. This method
is offen called automatically when you call Foundation method, such as
add objects to an array, but assign operator "=" will not affect
reference count
[AObject release] decrease reference count by 1.
This method is offten called automatically also when you call Foundation
method, such as remove objects from an array. If reference count is 0,
the object is no longer used, autoreleas pool will free memory used by
that object.
[AObject retainCount] get current reference count;
V)
If your program generates a lot of temporary object (This easily happen
when executing code inside a loop ), you can create multiple
autorelease pool, i.e.:
for( i = 0; i < XXX: i++)
{
NSAutoReleasePool *poolTmp = [[NSAutoReleasePool alloc] init];
//Lots of work with temporary objects here.
[poolTmp drain];
}
VI) Additional Notes
a) If current autorelease pool is destroyed by calling [pool drain],
and then create a new one, you must call [obj autorelease] to add object
to new autorelease pool;
b) Destroy autorelease pool by calling [pool drain] will not affect reference count of objects in the autorelease pool;
c) Add objects to autorelease pool by calling [obj autorelease] will not affect its reference count.
d) In addition to autorelease pool, Objective-C has garbage collection,
like that for Java, but for some releases(please refer to the book),
we'd better use autorelease pool, - Garbage Collection
As of Objective C 2.0, an alternate form of memory management, known as garbage
collection, became available.With garbage collection, you don’t have to worry about retaining and releasing objects, autorelease pools, or retain counts.The system automatically keeps tracks of what objects own what other objects, automatically freeing up (or garbagecollecting) objects that are no longer referenced as space is needed during the program’s execution.
When garbage collection is enabled, your program can still make its retain ,
autorelease , release , and dealloc method calls. However, they’ll all be ignored.
- NSCopying, NSMutableCopying
A protocol to copy objects
阅读(1900) | 评论(0) | 转发(0) |