Skip to content

Instantly share code, notes, and snippets.

@onurhuseyincantay
Last active January 16, 2019 13:08
Show Gist options
  • Save onurhuseyincantay/17e35536ad99628f4945842bdd3760c0 to your computer and use it in GitHub Desktop.
Save onurhuseyincantay/17e35536ad99628f4945842bdd3760c0 to your computer and use it in GitHub Desktop.
Basic Objective-C Declarations
// NSString
NSString *someAllocInitString = [[NSString alloc] initWthString: @“The String”];
NSString *someLiteralDeclaredString = @"The String";
// NSArray
NSArray *someAllocInitArray = [NSArray arrayWithObjects:@“firstObject”,@“secondObject”,@“thirdObject”];
NSArray *someLiteralDeclaredArray = @[@“firstObject”,@“secondObject”,@”thirdObject”];
// NSDictionary
NSDictionary *someAllocInitDictionary = [NSDictionary dictionaryWithObjectAndKeys : @“firstValue”,@“firstKey”
,@“secondValue”,@“secondKey”]
// This would be more confusing because it has an order of value key not key value
NSDictionary *someLiteralDeclaredDictionary = @{@“firstKey”: @“firstValue”,@“secondKey”:@”secondValue”};
// If we want to get a specific value for an key without literals it would be like;
NSString *firstValue = [someDictionary objectForKey:@“firstKey”];
//But with literals it would something like this;
NSString *firstValue = someDictionary[@“firstKey”];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment