EzDevInfo.com

jastor

Auto translates NSDictionary to instances of Objective-C classes, supporting nested types and arrays

Using Jastor to translate JSON/NSDictionary to Typed Swift classes

I'm going through Jastor's documentation:

There's an Objective-C implementation for returning arrays:

+ (Class)categories_class {
    return [ProductCategory class];
}

This is my attempt at converting it to Swift, however it ends up not returning anything so I don't think it's implemented correctly:

#<_TtC4TestApp4Room: id = (null) {
    resultCount = 50; // 50 is returning fine
    results =     ( // results is not
    );
}>

NSDictionary response:

{
  "resultCount" : 50,
  "results" : [
    {
      "collectionExplicitness" : "notExplicit",
      "discCount" : 1,
      "artworkUrl60" : "http:\/\/a4.mzstatic.com\/us\/r30\/Features\/2a\/b7\/da\/dj.kkirmfzh.60x60-50.jpg",
      "collectionCensoredName" : "Changes in Latitudes, Changes in Attitudes (Ultmate Master Disk  Gold CD  Reissue)"
    }
   ]
}

Music.swift (not quite sure how to implement the results_class() method)

class Music : Jastor {

    var resultCount: NSNumber = 0
    var results: NSArray = []

    class func results_class() -> AnyClass {
        return Author.self
    }
}

Author.swift

class Author {

    var collectionExplicitness: NSString = ""
    var discCount: NSNumber = 0
    var artworkUrl60: NSString = ""
    var collectionCensoredName: NSString = ""

}

Source: (StackOverflow)