iOS Simple Network Framework
The idea behind this framework is to make it easy to fetch content from the network without having to import a huge set of dependencies (aka AlamoFire, AFNetworking, RestKit, etc...)
The main item to use is the Fetcher
in the Fetcher.swift
file. Its only responsability is to fetch data from an end-point.
init
with aURLSession
and anAPI end-point
:fetch
content from asegment
Gist "https://gist.github.com/ehtd/4606eba95ef43965251617e1290a159d.js"
// Import Hermes module
import Hermes
.
.
.
// Keep in class scope
fileprivate let fetcher: Fetcher
init() {
// Session can be provided externally and shared among
// multiple fetchers in case your fetchers may need to share cached content
// or share the same session cache rules.
let session = URLSession(configuration: URLSessionConfiguration.default)
// Useful to separate the end-point from segments for example when using
// development APIs that share the same segment, but different end-point.
let endpoint = "https://hacker-news.firebaseio.com/v0/"
// Init
fetcher = Fetcher(with: session, apiEndPoint: endpoint)
}
func getContent() {
// With this segment, the final resolved path will be:
// "https://hacker-news.firebaseio.com/v0/topstories.json"
let segment = "topstories.json"
// Call fetch
fetcher.fetch(segment, success: { (response) in
// Content retrieved
print(response)
}, error: { (error) in
// Something failed
print(error)
})
}
Take a look at FetcherTests.swift
for more examples on how to use it.
- Create a
cartfile
with the content:
github "https://github.com/ehtd/Hermes" ~> 1.0
-
Add Copy framework phase to your target
Shell:
/usr/local/bin/carthage copy-frameworks
Input files:
$(SRCROOT)/Carthage/Build/iOS/Hermes.framework
Output files:
$(DERIVED_FILE_DIR)/Hermes.framework
Check Carthage for additional setup information.