2 daffodilgirl DaffodilGirl 于 2012.12.11 10:10 提问

在Xcode中创建NSMutableArray

现在要创建NSMutableArray ,像下面的例子一样。不知道怎么实现?

(
        {
        businessName = "IBM Business Continuity & Recovery Service";
        city = "Costa Mesa";
        phone = "(714) 668-6900";
        state = CA;
        street = "600 Anton Blvd";
        zip = 92626;
    },
        {
        businessName = "IBM Sanno";
        city = Lomita;
        phone = "(310) 626-0613";
        state = CA;
        street = "25835 Appian Way";
        zip = 90717;
    },
        {
        businessName = "Ewert's IBM Typewriter Service";
        city = "";
        phone = "(559) 732-3215";
        state = "";
        street = "";
        zip = "";
    },
)

请指教。

2个回答

prettYYoyic
prettYYoyic   2012.12.11 10:54
已采纳

动态添加dictionary。

NSMutableArray *dictionaries = [[NSMutableArray alloc] init];

NSDictionary *exampleDict = [[NSDictionary alloc] initWithObjectsAndKeys:
@"IBM Business Continuity & Recovery Service", @"businessName", 
@"Costa Mesa", @"city", 
@"(714) 668-6900", @"phone", 
@"CA", @"state", 
@"600 Anton Blvd", @"street", 
@"92626", @"zip", nil];

[dictionaries addObject:exampleDict];
redCoral_
redCoral_   2012.12.11 14:51
NSArray *array = @[
    @{
        @"businessName" : @"IBM Business Continuity & Recovery Service",
        @"city" : @"Costa Mesa",
        @"phone" : @"(714) 668-6900",
        @"state" : @"CA",
        @"street" : @"600 Anton Blvd",
        @"zip" : @(92626)
    },
    @{
        @"businessName" : @"IBM Sanno",
        @"city" : @"Lomita",
        @"phone" : @"(310) 626-0613",
        @"state" : @"CA",
        @"street" : @"25835 Appian Way",
        @"zip" : @(90717)
    },
    @{
        @"businessName" : @"Ewert's IBM Typewriter Service",
        @"phone" : @"(559) 732-3215"
    }
];
Csdn user default icon
上传中...
上传图片
插入图片