Objective-C-資料模型

來源:互聯網
上載者:User

標籤:

NSDictionary *daiwei = @{

                                 @"name":@"David Beckham",

                                 @"age":@"38",

                                 @"gender":@"true",

                                 @"wife":@{

                                         @"name":@"Victoria Beckham",

                                         @"age":@(39),

                                         @"team":@"Spice Girls"

                                         },

                                 @"children":@[

                                         @"Brooklyn",@"Romeo",@"Cruz",@"Harper"]

                                 };

//        從daiwei;裡面找到children的值;放到nameList的數組裡面;

        NSArray *nameList = daiwei[@"children"];

//        盛方便小孩的數組(最終要把這個數組放到man對象childList屬性裡面)

        NSMutableArray *childArray = [NSMutableArray array];

//        把小孩添加到childArray這個數組裡面的過程;

        for (NSString *name in nameList) {

            ChildModel *child = [[ChildModel alloc]init];

            child.name = name;

            [childArray addObject:child];

//            每次初始化一個小孩放到childArray裡面去,迴圈的;

        }

        NSLog(@"%@",childArray);

        WIfeModei *wife = [[WIfeModei alloc]init];

        wife.name = daiwei[@"wife"][@"name"];

        wife.age = [daiwei[@"wife"][@"age"]intValue];

        wife.team = daiwei[@"wife"][@"team"];

        

        

        ManModei *man = [[ManModei alloc]init];

        man.name = daiwei[@"name"];

        man.age = [daiwei[@"age"]intValue];

        man.ganrd = daiwei[@"gender"];

        man.wife = wife;

        man.childList = childArray;

        NSLog(@"%@",man);

 

 

 

#import "WIfeModei.h"

@implementation WIfeModei

-(NSString *)description

{

    return [NSString stringWithFormat:@"%@%d%@",self.name,self.age,self.team];

}

@end

 

#import <Foundation/Foundation.h>

@interface WIfeModei : NSObject

@property NSString *name;

@property int age;

@property NSString *team;

 

 

#import <Foundation/Foundation.h>

@interface ChildModel : NSObject

@property NSString *name;

@property NSString *team;

@property NSString *age;

 

 

#import "ChildModel.h"

@implementation ChildModel

- (NSString *)description

{

   return self.name;

}

 

 

#import <Foundation/Foundation.h>

@class WIfeModei;

@interface ManModei : NSObject

@property NSString *name;

@property int age;

@property NSArray *childList;

@property WIfeModei *wife;

@property NSString *ganrd;

 

#import "ManModei.h"

@implementation ManModei

- (NSString *)description

{

    return [NSString stringWithFormat:@"%@%d%@%@%@",self.name,self.age,self.childList,self.wife,self.ganrd];

}

Objective-C-資料模型

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.