Reputation: 1383
Is it possible to use an array in a subclass of JSONModel in Swift? Or is it a limitation as it is not updated yet?
If I do this in Objective-C, in the .h file:
@interface RecommendationModel : JSONModel
@property (strong, nonatomic) NSArray<VenueModel>* recommendations;
@end
It works fine.
But, if I do this in Swift:
class RecommendationModel: JSONModel {
var recommendations : [VenueModel] = []
}
It didn't work. The app runs, but when trying to read JSON, it breaks with the message:
Terminating app due to uncaught exception 'JSONModelProperty type not allowed', reason: 'Property type of App_iOS.RecommendationModel.recommendations is not supported by JSONModel.'
The JSON, and the VenueModel
class are identical for Objective-C and Swift.
Any way to make it work in Swift?
Upvotes: 4
Views: 1698
Reputation: 1154
I was having the same problem. Because JSONModel doesn't understand the swift so you have to give objetive-c. Try this:
var recommendations: NSArray = [VenueModel()]
@marintodorov, can you verify?
Upvotes: 1