objective-c-Data Model

Source: Internet
Author: User

Nsdictionary *daiwei = @{

@ "name": @ "David Beckham",

@ "Age": @ "38",

@ "Gender": @ "true",

@ "Wife": @{

@ "name": @ "Victoria Beckham",

@ "Age": @ (39),

@ "Team": @ "Spice Girls"

},

@ "Children": @[

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

};

from Daiwei; Find the value of children; put it in the namelist array;

Nsarray *namelist = daiwei[@ "Children"];

An array of easy-to-reach children (this array is eventually placed in the Man Object Childlist property)

Nsmutablearray *childarray = [Nsmutablearray array];

The process of adding a child to the Childarray array;

For (NSString *name in NameList) {

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

Child.name = name;

[Childarray Addobject:child];

Each time a child is initialized and put into the childarray, it loops;

}

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-Data Model

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.