I am looking into a custom scenario wherein I need to create a object of a defined class during the run time and set attributes to it as well. Something like this in objective-C
//The Model class
@interface Car:NSObject
{
@property(nonatomic,copy) NSString * numberOfDoors;
@property(nonatomic,copy) NSString * carModel;
@property(nonatomic,copy) NSString * carMake;
@property(nonatomic,copy) NSString * carBrand;
}
Creating a custom run time object for the above class (not sure whether this is right but just speaking from the top of my head)
id myNewObject = [[NSClassFromString(@"Car") alloc]init];
[myNewObject setValue:@"4 doors" forKeyPath:@"numberOfDoors"];
[myNewObject setValue:@"Prius" forKeyPath:@"carModel"];
[myNewObject setValue:@"2014" forKeyPath:@"carMake"];
[myNewObject setValue:@"Toyota" forKeyPath:@"carBrand"];
So my intention here is to create a object mapping module that would take the class name and a object mapping information that will describe how to map/create a model object from a JSON response (something very similar to RestKit minus the core data sync part).
I know this can be done with objective C but not sure how this would be applicable to swift classes
any help is appreciated.