How to create a JSONModel class in Objective-C with same variable in two types?

225 views Asked by At

I have a JSONModel class in Objective-C. I am initializing this with JSON returned by a server.

#import "JSONModel.h"

@protocol MyJsonMoodelClass

@end

@interface MyJsonMoodelClass : JSONModel

@property (nonatomic, strong)  NSNumber <Optional>  * idFilm;

This JSON contains a variable called idFilm, and sometimes is returned of type NSNumber but another is returned in array.

For exaple:

idFilm : 5

or

idFilm : [2, 5]

How could I control this and how could I have the same variable defined by two types, NSNumber and NSArray? Is possible control this?

1

There are 1 answers

0
francesco.venica On

if you override "set" method? something like this:

- (void)setIdFilm:(id)idFilm
{
    if([idFilm isKindOfClass:NSArray])
        ...
    else
        ...
}

I don't know if can work but can be a starting point