0

i want to create custom object to get set value on it.

-(id)initWithURLString:(NSString *)url
{
if (self = [super init])
{
    self.XXX = XXX;
    self.YYY = YYY:
}
return self;
}

until here i am ok, i can set / get when i call my custom class. however i need more detailed one. i want to add sub keys to my object variables as like.

myObj.XXX.x

myObj.YYY.y

also i want to set / get sub keys. any idea much appreciated. thank you.

1 Answer 1

1

In that case, you need the type of XXX to have its own properties.

For instance,

An example subtype interface:

@interface MySubtype : NSObject
  int x;
  int y;
}

@property(nonatomic, assign) int x;
@property(nonatomic, assign) int y;

And an example interface for your main type:

@interface MyType : NSObject
  MySubtype *subType;
}

@property(nonatomic, retain) subType;
Sign up to request clarification or add additional context in comments.

2 Comments

hi @aleph_null, yes thas works but every type minimum two different sub types some 10+ and in total i have 30+ type. i thought there is easier way out there? or no?
I don't think so, sorry. There's no getting around having to declare all the fields you plan to use. Though you may be able to use existing ios classes or find ways to use structures such as arrays to minimize the number of subtypes you actually need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.