2. Objectivewhat?
Language appeared around the early 80’s @ NeXT
It’s nothing more than a thin layer on top of C
Object-OrientedLanguage with SmallTalk-Style messaging
Can be compiled with GCC, so you can try it on Windows!
Sexta-feira, 26 de Julho de 13
3. “Talkischeap.Showmethecode”
LinusTorvalds
Person *person = [[Person alloc] init];
[person setFirstName:@"Linus"];
[person setLastName:@"Torvalds"];
NSLog(@"Talk is indeed cheap - %@ %@", [person firstName],
[person lastName]);
Object allocation
Setter’s
A simple print, that takes the 2nd and 3rd parameter value and replaces the %@’s
It’s called a formatter specifier, if you wonder
Getter
Sexta-feira, 26 de Julho de 13
4. Andevenmorecode.....+ (NSURLRequest *)requestFromDictionary:(NSDictionary *)parametersDictionary
{
NSURL *webserviceURL = [SFBucketCallsManager
buildURLFromParameters:parametersDictionary];
SFAccountInfo *accountInfo = [parametersDictionary objectForKey:WS_ACCOUNT_INFO_KEY];
// Get the user's name and password
NSString *userName = accountInfo.accountName;
NSString *password = accountInfo.accountPassword;
// Transform the Username & Password to base64
NSString *authStr = [NSString stringWithFormat:@"%@:%@",userName, password];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData
base64EncodedString]];
// Creation of the Request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:webserviceURL];
[request setValue:authValue forHTTPHeaderField:AUTH];
[request setHTTPMethod:[parametersDictionary objectForKey:WS_METHOD]];
[request setTimeoutInterval:15.f];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
if ([parametersDictionary objectForKey:WS_REQUEST_BODY_KEY])
{
NSString *postString = [parametersDictionary objectForKey:WS_REQUEST_BODY_KEY];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
}
return request;
}
Sexta-feira, 26 de Julho de 13
5. NS,NSeverywhere!
No concept of or . So to keep classes with the same name
without having conflicts, we put a before the name of the class.Prefix
packages namespaces
So.......
NSArray
NSString
NSLog
NSDictionaryNSInteger
NSSet
NSConnection
NSURL
NSObject
NSOperation
NSDate
NSData
+around220...
NSCoding
Sexta-feira, 26 de Julho de 13
8. Bigdeal...Sowhatarethe
advantages?
Dynamicnature (it’s really fun!)
Memory managment is done @ compile time
EnforcestheMVCpattern
Language designed with large code bases in mind
YoucanmixCinyourcode!(now we are getting somewhere)
Icouldkeepgoing....
Sexta-feira, 26 de Julho de 13