NewsAPISwift is a Swift client for News API V2, a service that provides breaking news headlines, and search for articles from over 30,000 news sources and blogs.

Overview

NewsAPISwift

CI Status Carthage compatible Version License Platform codecov codebeat badge

NewsAPISwift is a Swift client for News API V2, a service that provides breaking news headlines, and search for articles from over 30,000 news sources and blogs.

Usage

NewsAPISwift offers two functions to which sources and top headlines can be requested.

Sources

The first functions is used for listing all available sources indexed by the service. Three parameters can be passed in order to filter results.

Parameter Description
Category The category you would like to get sources for. The possible values are: business, entertainment, general, health, science, sports, technology. Default: all categories.
Language The language you would like to get sources for. The possible values are: ar, de, en, es, fr, he, it, nl, no, pt, ru, se, ud, zh. Default: all languages.
Country The country you would like to get sources for. To get the full list of supported countries, please head to the official documentation. Default: all countries.

Example

import NewsAPISwift

let newsAPI = NewsAPI(apiKey: "YourKeyHere")

newsAPI.getSources(category: .technology, language: .en, country: .us) { result in
    switch result {
    case .success(let sources):
        // Do something with returned sources
    case .failure(let error):
        // Handle error
    }
}

Top Headlines

The second function is used for listing top headlines. It is possible to request headlines for a specific country, a single or multiple sources, as well as keywords.

To get a full list of supported parameters, check the official documentation for the service.

Example

Top Headlines about the weather:

import NewsAPISwift

let newsAPI = NewsAPI(apiKey: "YourKeyHere")

newsAPI.getTopHeadlines(q: "weather") { result in
    switch result {
    case .success(let headlines):
        // Do something with returned headlines
    case .failure(let error):
        // Handle error
    }
}

Top Headlines from BBC News:

newsAPI.getTopHeadlines(sources: ["bbc-news"]) { result in
    switch result {
    case .success(let headlines):
        // Do something with returned headlines
    case .failure(let error):
        // Handle error
    }
}

Top Headlines from the US about technology:

newsAPI.getTopHeadlines(category: .technology, country: .us) { result in
    switch result {
    case .success(let headlines):
        // Do something with returned headlines
    case .failure(let error):
        // Handle error
    }
}

It is also possible to limit the number of articles returned by passing the pageSize parameter. Since there could be more results, pagination is also possible.

newsAPI.getTopHeadlines(pageSize: 20, page: 1) { result in
    switch result {
    case .success(let headlines):
        // Do something with returned headlines
    case .failure(let error):
        // Handle error
    }
}

Example Application

To run the example project, clone the repo, and run pod install from the Example directory first. Then, open Example.xcworkspace and run the project.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate NewsAPISwift into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'NewsAPISwift', '~> 2.0'
end

Then, run the following command:

$ pod install

Carthage

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

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

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

github "lucaslimapoa/NewsAPISwift"

Run the following command to build the framework:

carthage update

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

License

NewsAPISwift is available under the MIT license. See the LICENSE file for more info.

NOTE: This library and its author are not endorsed by or affiliated with newsapi.org.

You might also like...
Fancy news app that diwnloads data from new.com api and shows it in a paging collectionview.
Fancy news app that diwnloads data from new.com api and shows it in a paging collectionview.

Fancy news reader PAging collection view that shows latest news from techcurch.com and displays full content in a detail page, was built to practice t

Hackers is an elegant iOS app for reading Hacker News written in Swift.
Hackers is an elegant iOS app for reading Hacker News written in Swift.

Hackers Hackers is an iPhone and iPad app for reading Hacker News on the go. It's optimised for quickly catching up on the latest news and comments wi

A Hacker News reader iOS app written in Swift.
A Hacker News reader iOS app written in Swift.

HackerNews A Hacker News reader iOS app written in Swift. Features View "top", "newest", and "show" posts from Hacker News. Read posts using the SFSaf

Small iOS app to show some COVID-19 health, data, news and tweets âš¡
Small iOS app to show some COVID-19 health, data, news and tweets âš¡

covid19.swift Small iOS app to show some COVID-19 health, data, news and tweets âš¡ Requirements Xcode 12, iOS 14 Credits API: COVID-19 API: News Tweets

NY Times is an Minimal News 🗞 iOS application built to describe the use of SwiftSoup and CoreData with SwiftUI.
NY Times is an Minimal News 🗞 iOS application built to describe the use of SwiftSoup and CoreData with SwiftUI.

🗽 NY Times is an Minimal News 🗞 iOS app 📱 built to describe the use of SwiftSoup and CoreData with SwiftUI🔥

📰 iOS news app in the style of the NYT, WSJ, CNN, BBC, FB, Twitter, Reddit & more - Includes a tvOS app :tv:
📰 iOS news app in the style of the NYT, WSJ, CNN, BBC, FB, Twitter, Reddit & more - Includes a tvOS app :tv:

News iOS news app in the style of Apollo, Apple News, Axios, BBC, CNN, Facebook, Facebook News, FastNews, Flipboard, Lil News, NBC News, Reddit, The N

News app that using the NewsAPI
News app that using the NewsAPI

Appcent-Case It's News app that using the NewsAPI. Features Search News Show News Detail Add Favorite Delete Favorite Clear Favorites Share News Show

SimpleRSSReader is a simple app showing the latest Apple news.
SimpleRSSReader is a simple app showing the latest Apple news.

SimpleRSSReader SimpleRSSReader is a simple app showing the latest Apple news. It demos the usage of following stuff: How to use XML Parser Delegate t

This is my version of the H4X0R News app, taught by Angela Yu on the iOS Development Bootcamp.
This is my version of the H4X0R News app, taught by Angela Yu on the iOS Development Bootcamp.

H4X0R News 📰 (I didn't choose the name btw) What is it about? H4X0R News is an app that shows the front page news from Hacker News Website, and when

Comments
  • unable to parse

    unable to parse

    I've been using NewsApi . and it works perfectly but all of a sudden I got this error :

    Thread 10: Fatal error: unableToParse i didn't understand what i did wrong.

    My stackoverflow post is here

    please help

    opened by nessrinehafi 0
  • newsAPI.getTopHeadlines Error

    newsAPI.getTopHeadlines Error

    Hey Lucas,

    Love your Swift Client for the News API. Have been using it for a while with no problems. However, just recently, the function "newsAPI.getTopHeadlines(country: NewsCountry(rawValue: String)" started to give me the error "unableToParse" whenever I pass in "us" as the country. It works with other countries, just not "us."

    I know it's not how I am passing the value of the country in, as I use the "newsAPI.getSources(country: NewsCountry(rawValue: String)" and it works when I pass in "us."

    Any help would be appreciated. Thank you!

    opened by gcurbelo123 1
Owner
Lucas Lima
Computer Engineer. iOS Engineer and tech enthusiast.
Lucas Lima
This app can be used to search for New York Times articles

NY Times Article Search This app can be used to search for New York Times articles. The articles are populated by matching keywords. Here are the feat

Alexei Tulloch 0 Feb 10, 2022
App that shows recently posted articles about Android or iOS on Hacker News

App that shows recently posted articles about Android or iOS on Hacker News

Jose Moffa 0 Nov 9, 2021
Headline News View Example App for iOS. You can display the articles fetched by rss.

HeadLineNews-ObjC Headline News View Example App for iOS. You can display the articles fetched by rss. PiP(Picture in Picture) is also supported DEMO

null 11 May 31, 2022
Matthew Ogtong 0 Jan 20, 2022
Daily News is a news app with good looking user interface ! Apps architecture is MVVM and used RxSwift for binding.

Daily News Hey ! Daily News is a news app with good looking user interface ! Apps architecture is MVVM and used RxSwift for binding. Architecture I pr

Latif Atci 39 Dec 13, 2022
News app to see daily news from new York Times

News This project is demo project for newyork time apis news feed. Generally thi

kamalesh 0 Dec 18, 2021
News - A news app that use NewsAPI

News app - UIKit This is a news app that use NewsAPI - Features MVC design patte

Muhammed Faruk Söğüt 1 Jan 4, 2022
News App for Latinx News built in UIKit programmatically

LatinxNewsApp News App for Latinx News built in UIKit programmatically Overview LatinxNewsApp is a design taken from a bigger idea. It is a news app t

Bryan Gomez 1 Apr 21, 2022
Hacker News client for macOS

HNReaderApp This is the public repository for the HNReader macOS application. You can report any issue and suggest/request new features in the issue s

Mattia Righetti 186 Oct 14, 2022
HackerWeb 2: A read-only Hacker News client.

HackerWeb 2 A read-only Hacker News client. Only 30 front-page stories. No more no less. Revolutionary comments thread UI. Smart collapse and easy nav

Chee Aun 51 Dec 27, 2022