Giter VIP home page Giter VIP logo

feedkit's Introduction

FeedKit

An RSS and Atom feed parser written in Swift

build status carthage compatible cocoapods compatible cocoapods compatible language documentation

Features

Requirements

ios tvos watchos mac os xcode

Installation

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To give FeedKit a try with an example project, run the following command:

$ pod try FeedKit

To integrate FeedKit into your Xcode project, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
  pod 'FeedKit', '~> 5.0'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a dependency manager that builds your dependencies and provides you with binary frameworks.

To install Carthage with Homebrew use the following command:

$ brew update
$ brew install carthage

To integrate FeedKit into your Xcode project using Carthage, specify it in your Cartfile:

github "nmdias/FeedKit" ~> 5.0

Build the framework:

$ carthage update

Then, drag the built FeedKit.framework into your Xcode project.

Manually

Drag FeedKit.xcodeproj into your Xcode project.

It should appear nested underneath your application's blue project icon.

Click on the + button under the "Embedded Binaries" section of your app's target and select the FeedKit.framework that matches the desired platform.

Usage

Feed Parsing

RSS

import FeedKit

let URL = URL(string: "http://images.apple.com/main/rss/hotnews/hotnews.rss")!

FeedParser(URL: URL)?.parse({ (result) in
    result.rssFeed // An `RSSFeed` model
})

Atom

FeedParser(URL: URL)?.parse({ (result) in
    result.atomFeed // An `AtomFeed` model
})

Aditional initializers can also be found for Data and InputStream objects.

Parse Result

Multiple FeedType's and, or Error handling can be acomplished using the Result enum

FeedParser(URL: URL)?.parse({ (result) in
    
    switch result {
    case .RSS(let rssFeed):
        print(rssFeed) // An `RSSFeed` model
    case .Atom(let atomFeed):
        print(atomFeed) // An `AtomFeed` model
    case .Failure(let error):
        print(error) // An `NSError` object
    }
    
})

Model Preview

RSSFeed

FeedParser(URL: URL)?.parse({ (result) in
    
    guard let feed = result.rssFeed where result.isSuccess else {
        print(result.error)
        return
    }
    
    print(feed.title)                      // The feed's `Title`
    print(feed.items?.count)               // The number of articles
    print(feed.items?.first?.title)        // The feed's first article `Title`
    print(feed.items?.first?.description)  // The feed's first article `Description`
    print(feed.items?.first?.pubDate)      // The feed's first article `Publication Date`
    
})

Refer to the RSSFeed documentation for the complete model properties and description

AtomFeed

FeedParser(URL: URL)?.parse({ (result) in
    
    guard let feed = result.atomFeed where result.isSuccess else {
        print(result.error)
        return
    }
    
    print(feed.title)                    // The feed's `Title`
    print(feed.entries?.count)           // The number of articles
    print(feed.entries?.first?.title)    // The feed's first article `Title`
    print(feed.entries?.first?.summary)  // The feed's first article `Summary`
    print(feed.entries?.first?.updated)  // The feed's first article `Updated Date`
    
})

Refer to the AtomFeed documentation for the complete model properties and description

Background Parsing

DispatchQueue.global(qos: .userInitiated).async {
    // Run parsing in a background thread
    FeedParser(URL: URL)?.parse({ (result) in
        DispatchQueue.main.async {
            // Perform updates in the main thread when finished
        }
    })
}

License

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

feedkit's People

Contributors

nmdias avatar bamurph avatar brettohland avatar

Watchers

James Cloos avatar Jeremy Vizzini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.