How to create an NSDictionary with multiple keys?

前端 未结 5 852
臣服心动
臣服心动 2020-12-30 12:34

I am not sure if what I am going to ask is actually an NSDictionary with multiple keys but ok.

What I want to do is create an NSDictionary

5条回答
  •  不知归路
    2020-12-30 13:20

    Now with Objective-C literals there is a much better, easier, and cleaner way of accomplishing this. Here is your exact dictionary with this new syntax:

    NSDictionary *dictionary = @{
        @"eventData": @{
            @"eventDate": @"Jun 13, 2012 12:00:00 AM",
            @"eventLocation": @{
                @"latitude": @43.93838383,
                @"longitude": @-3.46
            },
            @"text": @"hjhj",
            @"imageData": @"raw data",
            @"imageFormat": @"JPEG",
            @"expirationTime": @1339538400000
        },
        @"type": @"ELDIARIOMONTANES",
        @"title": @"accIDENTE"
    };
    
    // Prints: "43.93838383"
    NSLog(@"%@", dictionary[@"eventData"][@"eventLocation"][@"latitude"]);
    

提交回复
热议问题