Latest 1.0
Homepage https://github.com/zolomatok/Muttley
License MIT
Platforms ios 8.0, requires ARC
Authors

Logo

pod
language
platform
license

Muttley is a lightweight networking library written for Swift.

Features

  • [x] Generic response parsing
  • [x] Concurrent requests for the same resource do not start new network request, but each request will be returned with the data
  • [x] LRU memory cache with configurable limit
  • [x] Cancellable requests
  • [x] Progress reporting
  • [x] Configurable via URLSessionConfiguration

Requirement

  • iOS 8.0+

Install

CocoaPods

pod 'Muttley'

Manually

  1. Clone the repo
  2. Build the project
  3. Drag & drop the framework into your project (tick ‘copy’ or set the path of ‘Framework Search Paths’ in your Build Settings)
  4. In your Target settings under the ‘General’ tab add Muttley to the ‘Embedded Binaries’ table
  5. Make sure to ‘import Muttley’ in your source

How to use

Fetching

let request = Request(url: someURL)
Muttley.fetch(request: request) { [weak self] (data: Data?, error) in

}

All but the url parameter can be omitted from the Request initializer.

Note the weak self in the capture list.

Parsing

let request = Request(url: someURL, parser: ImageParser())
Muttley.fetch(request: request) { (image: UIImage?, error) in

}

You can supply your own parser class that conforms to the simple Parser protocol:

public protocol Parser {
    func parse(data: Data?) -> Any?
}

A simple image and JSON parser is provided by the Muttley.

Progress reporting

let request = Request(url: someURL) { [weak self] (progress) in
    self?.progressView.progress = Float(progress)
}
Muttley.fetch(request: request) { (image: UIImage?, error) in

}

Configuration

We can set the cache size limit of Muttley. Default is Int.max.

Muttley.maxCapacity = Int.max

Configuration is possible via URLSessionConfiguration.

This makes it possible to use Muttley with any kind of REST API by providing your own header fields.

let config = URLSessionConfiguration.default
config.httpAdditionalHeaders = ["Authorization": "someKey"]
let request = Request(url: "", configuration: config)
Muttley.fetch(request: request) { (data: Data?, error) in

}

License

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

Latest podspec

{
    "name": "Muttley",
    "version": "1.0",
    "summary": "Lightweight Networking for Swift",
    "homepage": "https://github.com/zolomatok/Muttley",
    "license": {
        "type": "MIT"
    },
    "authors": {
        "Zoltu00e1n Matu00f3k": "[email protected]"
    },
    "source": {
        "git": "https://github.com/zolomatok/Muttley.git",
        "tag": "1.0"
    },
    "requires_arc": true,
    "module_name": "Muttley",
    "platforms": {
        "ios": "8.0"
    },
    "ios": {
        "source_files": "Muttley/*.swift",
        "frameworks": [
            "UIKit",
            "Foundation"
        ]
    }
}

Pin It on Pinterest

Share This