4

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?

Pang
  • 9,564
  • 146
  • 81
  • 122
Fernando
  • 1,323
  • 2
  • 12
  • 17

1 Answers1

1

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?

Dilip Lilaramani
  • 1,126
  • 13
  • 28