Friday, October 22, 2010

Friday, October 22, 2010First Thing to Learn Objective C [2]

First, MVC, easlier to expend and maintenance!
If you know Java/J2EE, or .Net, you will know MVC is very important in the Software Applications.!
Model (Data), View (GUI), and C(Control with business Logic).
In Apple world, MFC are great!
Key-Value Coding(KVC)?Key-Value Observing(KVO)?Key-Value Binding(KVB)

Memory Management and Container
In Core libarary, Foundation Framework: including memory management, object management, container
Message Dispatching:
In Objective-C, using counter to manage the instance of jobs, before 2.0 version, programmer has to manually control the memory like in C, later adding new Garbage Collection Strtegies

Look at following codes:
NSString *aString = [[NSString alloc] initWithString:@"This is a demo."];
[aString release];
aString = nil;
--better do it all the time!!
- (NSString)demoString
{
NSString *result = [[NSString alloc] initWithString:@"This is a demo."];
[result autorelease];
return result;
}

ContainerListed here are most important and useful container, some developers love, but sometime give you some trouble as well.
There are 2 types: read-only or read-writable!

NSString
NSIndexSet
Any-type can save!!
NSArray
NSDictionary
NSSet
NSString *aString = [NSString stringWithString:@"This is a demo."];
NSNumber *aNumber = [NSNumber numberWithInteger:0];
NSArray *anArray = [[NSArray alloc] initWithObjects:aString, aNumber, nil];
Modifiable?? or Not?
NSMutableString, NSMutableArray, NSMutableDictioanry, NSMutableSet, NSMutableIndexSet
NSString *aString = [NSString stringWithString:@"This is a demo."];
NSNumber *aNumber = [NSNumber numberWithInteger:0];
NSMutableArray *aMutableArray = [NSMutableArray array];
[aMutableArray addObject:aString];
[aMutableArray addObject:aNumber];
[aMutableArray removeObjectAtIndex:0];
[aMutableArray removeAllObjects];

No comments:

Post a Comment