$ grep -r Tag: «json»

-rw-r--r-- 956B Sep 23, 2019 · B28AFA6 · ~1 min

Syntax sugar for JSON parsing in Swift

swift swift package json open source

JSON decoding and encoding became easy after adding Codable protocol in Swift 4.0. But during coding I wanted to have something shorter and more elegant than Do-Catch statement that looks like this:

var myModel: MyModel?
let decoder = JSONDecoder()

do {
    myModel = try decoder.decode(MyModel.self, from: data)
} catch {
    print(error.localizedDescription)
}

Or like this:

let myModel: MyModel? = try? decoder.decode(MyModel.self, from: data)

So I wrote a protocol with default implementation that allows to do decoding just like that:

let myModel = MyModel.decodeFromData(data: data)

And the same for encoding:

let data = MyModel.encode(fromEncodable: myModel)

All you need is just to add protocol conformance:

extension MyModel: Parseable {
    typealias ParseableType = Self
}

It's available on GitHub as a Swift Package: https://github.com/makoni/parsable

[↵] open page syntax-sugar-for-json-parsing-in-swift.md
-rw-r--r-- 836B Dec 5, 2011 · 2A8503A · ~1 min

Embedding the Facebook SDK in an iOS app

objective-c json ios шпаргалки полезное

A note to self. Instructions on where to download it and how to embed are in Facebook’s docs. Even though they updated the GitHub project recently (November 23 at the time of writing), they still ship an old version of the JSON framework bundled with it. And since my project already uses a newer version of that framework, the app wouldn’t compile.

Fix:

  1. after adding the SDK to the project, delete the JSON folder from the Facebook SDK;
  2. in FBRequest.m replace the line #import "JSON.h" with #import "SBJson.h";
  3. in the same file, replace
    SBJSON *jsonParser = [[SBJSON new] autorelease]
    with
    SBJsonParser *jsonParser = [[SBJsonParser new] autorelease]

Should work.

[↵] open page vstraivanie-facebook-sdk-v-ios-prilozhenie.md
-rw-r--r-- 5.1K Aug 23, 2011 · 897ADAD · ~4 min

Working with JSON (parsing) in Objective-C for iOS

ios разработка json twitter

Another post — to help things settle in my own head. About working with JSON in Objective-C, using parsing of tweets from Twitter’s public timeline as an example.

[↵] open page rabota-s-json-parsing-v-objective-c-pri-razrabotke-pod-ios.md
makoni@arm1:~/blog$ cd .. // ↵ back to all posts