字面值

  • 建立NSStringNSDictionaryNSArray、與NSNumber不可變物件時,應使用其字面值。請特別注意, 不可將nil值放進NSArray與NSDictionary的字面值,將會導致當掉。

    NSString *pfcLongName = @"Perfect Company";
    NSArray *names = @[@"Brian", @"Matt", @"Chris", @"Alex", @"Steve", @"Paul"];
    NSDictionary *productManagers = @{@"iPhone" : @"Kate", @"iPad" : @"Kamal", @"Mobile Web" : @"Bill"};
    NSNumber *shouldUseLiterals = @YES;
    NSNumber *buildingZIPCode = @10018;

Last updated

Was this helpful?