Saturday, August 10, 2013

NSMutableURLRequest *request = 
        [[NSMutableURLRequest alloc] initWithURL:
            [NSURL URLWithString:@"http://openapi.starbucks.com/v1/token"]];
 
[request setHTTPMethod:@"POST"];
 
NSString *postString = @"grant_type=password&client_id=myclientid&client_secret=mysecret&username=XTest&password=aaaaaa&scope=test_scope";
 
[request setValue:[NSString 
        stringWithFormat:@"%d", [postString length]] 
        forHTTPHeaderField:@"Content-length"];
 
[request setHTTPBody:[postString 
        dataUsingEncoding:NSUTF8StringEncoding]];
 
[[NSURLConnection alloc] 
        initWithRequest:request delegate:self];

Much like the HTTP request above, Objective C is used to build the application as a network of objects. Some of which are provided by Cocoa and Cocoa Touch. The language also makes use of framework classes. When building applications, object sends and receives messages.  Interface of the classes are defined with the @interface keyword. A class interface declares the methods and properties associated with the user class. Protocols define messaging contracts. A protocol is used to declare methods and properties that are independent of any class and is declared with the @protocol.
Values and Collections are specifiable just as in C language. Scalar types are used in situations where you just don't need the benefits of using an object. Additional primitive types such as NSInteger, NSUInteger, and CGFloat  are available. Numbers are represented by Instances of the NSNumber class.
Most collections are objects. Arrays are ordered collections. Arrays can be created and queried.Sets are unordered collections while Dictionaries collect key value pairs. Collections can be used to persist the object graph. Fast enumeration makes it easy to enumerate a collection. Most collections also support enumerator objects.

No comments:

Post a Comment