Latest 0.8.4
Homepage https://github.com/totocaster/JSONFeed
License MIT
Platforms ios 10.0
Authors

Swift Version
TravisCI
Platform
Twitter

Swift parser for JSON Feed — a new format similar to RSS and Atom but in JSON. For more information about this new feed format visit: https://jsonfeed.org


⚠️ Contributions are more than welcome! Here is how my todo list looks like now:

  • [x] Implement framework so its usable
  • [x] Proper in-line documentation
  • [x] Clear documentation in README (you are looking at it now)
  • [x] Add CococaPods support
  • [x] Add Carthage support
  • [ ] Add SPM support
  • [x] Add CHANGELOG to repository
  • [ ] Add much more elaborate tests
  • [x] Add Equtable for objects it makes sense
  • [ ] Consider adding byte and date formatter for JSONFeedAttachment

Thanks for checking-out JSONFeed!


Usage

Parsing a feed is super easy; just pass data from a response when creating a feed object and that’s it! Parsing happens upon initialization using JSONSerialization and if all goes well you’ll be able to access feed properties. In case initialization parameters are invalid, JSONFeed will throw JSONFeedError.

let feed = try? JSONFeed(data: responseData)

Alternatively you can create objects from a JSON string or JSON dictionary:

let dictionary: [String: Any] = ["title": "..."]
let feed = try? JSONFeed(json: dictionary)
let utf8String: String = "{'title':'..."
let feed = try? JSONFeed(jsonString: utf8String)

Documentation

Best way to learn about this library is to browse source files and inline documentation.

Below is quick description of objects and their responsibilities:

Feed and Properties in General

JSONFeed mirrors JSON Feed v1 spec defined keys almost one-to-one. Key names are "Swiftyfied" and strongly typed: all dates will be Date type, URLs — URL and so on. All fields defined by optional in spec are also Swift optionals in all objects.

Items

feed.items is an array of JSONFeedItem objects that wrap your items (posts, episodes for podcasts, etc.). It can not be nil, but can contain 0 elements.

contextText vs contentHTML

According to specs both are optional and both can be present in item at the same time. However if none of them is set by publisher, post will be discarded and not included in items array.

Items with no id

If id for the item is not set by publisher, item will be discarded and not included in items. This happens silently and no error will be thrown. Any other posts with set id will be peresent in array (unless both, contextText and contentHTML are missing). Reason for that in clearly elaborated in Suggestions for Feed Readers of JSON Feed v1 spec:

[…] there is one thing we insist on: any item without an id must be discarded. We come to this from years of experience dealing with feeds in other formats where unique identifiers are optional. Without unique identifiers, it’s impossible to reliably refer to a given item and its changes over time, and this is terrible for user experience and becomes a source of bug reports to you.

Attachments

Items can have attachments, they are wrapped in JSONFeedAttachment object. Attachment can be podcast episode, additional images, or any other media.

You can lear about attachment type using mimeType property. All attachments have url pointing to attached media. Those two are always present in all attachments.

Additionally JSONFeedAttachment have optional size (in bytes) and duration (in seconds) for relevant media files.

Author

Inert JSONFeedAuthor struct with name, avatar URL and web URL. Can be present both in JSONFeedItem and/or in JSONFeed.


Installation

CocoaPods

You can use CocoaPods to install JSONFeed by adding it to your Podfile:

platform :ios, '10.0'
use_frameworks!
pod 'JSONFeed'

Import JSONFeed wherever you plan to parse feed and follow instructions from above.

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/JSONFeed.framework to an iOS project.

github "totocaster/JSONFeed"

Manually

Download and drop all files from Classes folder into in your project.


License

JSONFeed is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "JSONFeed",
    "version": "0.8.4",
    "summary": "Simple JSONFeed parser written in Swift.",
    "description": "JSONFeed is Swift parser for JSON Feed - a new format similar to RSS and Atom nbut in JSON. https://jsonfeed.org",
    "homepage": "https://github.com/totocaster/JSONFeed",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Toto Tvalavadze": "[email protected]"
    },
    "social_media_url": "http://twitter.com/totocaster",
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/totocaster/JSONFeed.git",
        "tag": "0.8.4"
    },
    "source_files": [
        "Classes",
        "Classes/**/*.{h,m,swift}"
    ],
    "exclude_files": "Classes/Exclude",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This