Tuesday, 15 March 2011

objective c - Using Jastor to translate JSON/NSDictionary to Typed Swift classes -



objective c - Using Jastor to translate JSON/NSDictionary to Typed Swift classes -

i'm going through jastor's documentation:

there's objective-c implementation returning arrays:

+ (class)categories_class { homecoming [productcategory class]; }

this effort @ converting swift, ends not returning don't think it's implemented correctly:

#<_ttc4testapp4room: id = (null) { resultcount = 50; // 50 returning fine results = ( // results 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 implement results_class() method)

class music : jastor { var resultcount: nsnumber = 0 var results: nsarray = [] class func results_class() -> anyclass { homecoming author.self } }

author.swift

class author { var collectionexplicitness: nsstring = "" var disccount: nsnumber = 0 var artworkurl60: nsstring = "" var collectioncensoredname: nsstring = "" }

i'm using next syntax (adapted example):

static allow results_class = author.self

and works me.

other differences may or may not have effect:

i'm using int instead of nsnumber , string instead of nsstring (except arrays). i'm using implicitly wrapped optionals rather assigning default value each field

objective-c class swift jastor

No comments:

Post a Comment