jsonmodel / jsonmodel

Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Model collections not found in swift for xcode9&swift4

Tuluobo opened this issue · comments

In Xcode9 and Swift4:

Model:

// interface
@protocol People;
@interface People: JSONModel
@property(nonatomic, readwrite, strong) NSString *name;
@property(nonatomic, readwrite) NSInteger age;
@end

@protocol Car;
@interface Car: JSONModel
@property(nonatomic, readwrite, strong) NSString *name;
@property(nonatomic, readwrite, strong) NSString *color;
@end

@interface City: JSONModel
@property(nonatomic, readwrite) double area;
@property(nonatomic, readwrite, strong) NSMutableArray<People> *peoples;
@property(nonatomic, readwrite, strong) NSMutableArray<Car> *cars;
@end

// implementation
@implementation People
@end
@implementation Car
@end
@implementation City
@end

// Test
NSDictionary *dict = @{
    @"area" : @13,
    @"peoples" :  @[
                        @{@"name" : @"jony", @"age" : @23}, 
                        @{@"name" : @"july", @"age" : @25} ],
    @"cars" :  @[
                       @{@"name" : @"M", @"color" : @"red"}, 
                       @{@"name" : @"B", @"color" : @"green"} ]
};

NSError *err = nil;
City *city = [[City alloc] initWithDictionary:dict error:&err];
NSLog(@"%@", city);

In Objective-C , it's OK.

But in swift, the NSMutableArray not found.
not-found

qq20171017-103037

@Tuluobo any solutions? Have the same issue.

@YGeorge I rewrite 'getter' functions by hand-writing. But it's not a good idea.

@Tuluobo looks like need to migrate to another library now :(

If you can figure out how this needs to be resolved, please open a PR and I’ll be happy to get it included into the project. Unfortunately I don’t use Swift so am not able to help very much with finding a solution.