https://github.com/wesbillman/jsonfeed
JSONFeed parser for swift
https://github.com/wesbillman/jsonfeed
json jsonfeed swift
Last synced: over 1 year ago
JSON representation
JSONFeed parser for swift
- Host: GitHub
- URL: https://github.com/wesbillman/jsonfeed
- Owner: wesbillman
- License: mit
- Created: 2017-05-19T15:03:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-08-12T07:08:20.000Z (almost 6 years ago)
- Last Synced: 2025-02-28T07:51:33.531Z (over 1 year ago)
- Topics: json, jsonfeed, swift
- Language: Swift
- Size: 30.3 KB
- Stars: 27
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/wesbillman/JSONFeed)
[](https://codecov.io/gh/wesbillman/JSONFeed)
[](https://github.com/Carthage/Carthage)

# JSONFeed
Swift parsing for [JSON Feed](https://jsonfeed.org/) [Spec](https://jsonfeed.org/version/1)
## Installation
### Carthage
You can install [Carthage](https://github.com/Carthage/Carthage) with [Homebrew](http://brew.sh/) using the following command:
```bash
brew update
brew install carthage
```
To integrate JSONFeed into your Xcode project using Carthage, specify it in your `Cartfile` where `"x.x.x"` is the current release:
```ogdl
github "wesbillman/JSONFeed" "x.x.x"
```
### Swift Package Manager
To install using [Swift Package Manager](https://swift.org/package-manager/) have your Swift package set up, and add JSONFeed as a dependency to your `Package.swift`.
```swift
dependencies: [
.Package(url: "https://github.com/wesbillman/JSONFeed.git", majorVersion: 0)
]
```
### Manually
Add all the files from `JSONFeed/JSONFeed` to your project
## Usage
> See [JSONFeedTests](https://github.com/wesbillman/JSONFeed/blob/master/JSONFeedTests/JSONFeedTests.swift) for detailed usage examples
#### Load a feed from a dictionary
```swift
let dictionary =
let feed = try? JSONFeed(json: dictionary)
```
#### Load a feed from data
```swift
let data =
let feed = try? JSONFeed(data: data)
```
#### Load a feed from a json ut8f string
```swift
let string =
let feed = try? JSONFeed(string: string)
```
### Reading from a feed via URLSession
Using default configuration and URLSession
```swift
let reader = JSONFeedReader()
reader.read(string: "https://jsonfeed.org/feed.json") { (feed, error) in
if let error = error {
//bad things happened
}
if let feed = feed {
//good things happened
}
}
```
Using custom implemenation of URLSession (example: for unit testing)
```swift
let reader = JSONFeedReader(session: SomeCustomURLSession)
reader.read(string: "https://jsonfeed.org/feed.json") { (feed, error) in
if let error = error {
//bad things happened
}
if let feed = feed {
//good things happened
}
}
```