• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fetch, cache, and display images via HTTP in Swift.

Skeets

skeets

Skeets is a networking image library that fetches, caches, and displays images via HTTP in Swift. It is built off SwiftHTTP.

Features

  • Multi level cache. In-memory and disk caching.
  • Nonblocking IO. All HTTP and disk IO happen in the background, thanks to GCD.
  • Simple one method to load a remote image.
  • Robust, fast, and customizable caching.
  • Simple concise codebase at just a few hundred LOC.
  • handles redundant image requests, so only one request is sent for multiple queries

Full article here: Vluxe

Example

First thing is to import the framework. See the Installation instructions, on how to add the framework to your project.

import Skeets

Once imported, you can start requesting images.

//create a imageView
let imageView = UIImageView(frame: CGRectMake(0, 60, 200, 200))
self.view.addSubview(imageView)

//set the cache directory. Only have to do this once since `sharedManager` is a singleton
let paths = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)
ImageManager.sharedManager.cache.diskDirectory = "\(paths[0])/ImageCache"

//for OSX
//let paths = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)
//ImageManager.sharedManager.cache.diskDirectory = "\(paths[0])/\(NSBundle.mainBundle().bundleIdentifier!)/ImageCache"

ImageManager.sharedManager.cache.cleanDisk()

//fetch the image
ImageManager.fetch("http://vluxe.io/assets/images/logo.png",
    progress: { (status: Double) in
        println("updating some UI for this: \(status)") //useful if you have some kind of progress dialog as the image loads
    },success: { (data: NSData) in
        println("got an image!")
        imageView.image = UIImage(data: data) //set the image data
    }, failure: { (error: NSError) in
        println("failed to get an image: \(error)")
})

Cancel Request

Fetch requests can be cancelled when needed. This simply causes the closures not to be called.

ImageManager.cancel("http://vluxe.io/assets/images/logo.png")

Custom Cache

Skeets also supports customized caching and protocols. It is possible to implement your own custom cache by implementing the CacheProtocol. There is also a powerful default cache provided with a few customization options.

let c = ImageManager.sharedManager.cache as? ImageCache
if let cache = c {
    cache.diskAge = 60 * 60 //360 seconds or 1 hour (Default is 1 day).
    cache.imageCount = 10 //only 10 images will be stored in memory (Default is 50).
}

The cache can also be manually purged (e.g. memory warning is received).

ImageManager.sharedManager.cache.clearCache()

The disk can also be clean for possibly stale entries as well.

ImageManager.sharedManager.cache.cleanDisk()

Requirements

Skeets requires at least iOS 8/OSX 10.10 or above.

Skeets depends on SwiftHTTP. Make sure to import that framework as well before using Skeets.

If you encounter an issue with Skeets not building becuase SwiftHTTP can not be found, make sure to manually select SwiftHTTP framework from the build dropdown and build it. Then build your app again. This will cause the issue of SwiftHTTP not being found to be resolved.

Installation

Cocoapods

Check out Get Started tab on cocoapods.org.

To use Skeets in your project add the following 'Podfile' to your project

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

pod 'Skeets', '~> 0.9.5'

Then run:

pod install

Carthage

Check out the Carthage docs on how to add a install. The Skeets framework is already setup with shared schemes.

Carthage Install

Rogue

First see the installation docs for how to install Rogue.

To install Skeets run the command below in the directory you created the rogue file.

rogue add https://github.com/daltoniam/SwiftHTTP
rogue add https://github.com/daltoniam/Skeets

Next open the libs folder and add the Skeets.xcodeproj to your Xcode project. Once that is complete, in your "Build Phases" add the Skeets.framework to your "Link Binary with Libraries" phase. Make sure to add the libs folder to your .gitignore file.

Other

Simply grab the framework (either via git submodule or another package manager).

Add the Skeets.xcodeproj to your Xcode project. Once that is complete, in your "Build Phases" add the Skeets.framework to your "Link Binary with Libraries" phase.

Add Copy Frameworks Phase

If you are running this in an OSX app or on a physical iOS device you will need to make sure you add the Skeets.framework or SkeetsOSX.framework to be included in your app bundle. To do this, in Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar. In the tab bar at the top of that window, open the "Build Phases" panel. Expand the "Link Binary with Libraries" group, and add Skeets.framework or SkeetsOSX.framework depending on if you are building an iOS or OSX app. Click on the + button at the top left of the panel and select "New Copy Files Phase". Rename this new phase to "Copy Frameworks", set the "Destination" to "Frameworks", and add Skeets.framework or SkeetsOSX.framework respectively.

TODOs

  • Complete Docs
  • Add Unit Tests

License

Skeets is licensed under the Apache v2 License.

Contact

Dalton Cherry

More Repositories

1

Starscream

Websockets in swift for iOS and OSX
Swift
8,302
star
2

SwiftHTTP

Thin wrapper around NSURLSession in swift. Simplifies HTTP requests.
Swift
1,880
star
3

DCAnimationKit

A collection of animations for iOS. Simple, just add water animations.
Objective-C
801
star
4

JSONJoy-Swift

Convert JSON to Swift objects.
Swift
354
star
5

bumblebee

Abstract text processing and pattern matching engine in Swift. Converts text into NSAttributedStrings. Builtin markdown support.
Swift
109
star
6

tarkit

untar and tar files on iOS and OS X. Also supports gzip tars.
Objective-C
89
star
7

SwiftLog

Simple and easy logging in Swift.
Swift
72
star
8

UICustomizeKit

Base UIKit components extended to allow almost any customizations. Comes with Bootstrap and Flat UIs out of the box.
Objective-C
68
star
9

JSONJoy

Makes JSON a joy to use
Objective-C
56
star
10

FontAwesome-iOS

Provides easy access to font Awesome icons in iOS
Objective-C
46
star
11

DCLabel

Convert markdown or html text with embed content into a label.
Objective-C
31
star
12

DCCommentView

Comment view for iOS, same as messages app. Customizable.
Objective-C
30
star
13

Jazz

Easier layer animations in Swift
Swift
25
star
14

DCTextEngine

An engine that convert text to attributed strings and attributed strings to text. Supports HTML and markdown by default.
Objective-C
23
star
15

DCSideNav

Custom Navigation for iPad. Similar to iPad twitter app navigation.
Objective-C
17
star
16

DCDataViews

Simple and Powerful data management model for UITableView and UICollectionView to make simpler and faster to use.
Objective-C
10
star
17

GPLib-iOS

General Purpose iOS library
Objective-C
10
star
18

FeedView

A simple feed based view in Swift with customizable and delightful animations. Think UICollectionView with the animations you always wanted.
Swift
9
star
19

DCAvatar

A simple, asynchronous, network based avatar library for iOS and OSX
Objective-C
7
star
20

DCSlideOutViewController

Does the slide view thing as seen in Path app.
Objective-C
7
star
21

SimpleSwiftApp

Just a basic Swift App using SwiftHTTP and JSONJoy
Swift
6
star
22

DCXMPP

XMPP library for iOS or OSX in objective-c
Objective-C
5
star
23

XMLKit-objc

XML parsing in objective-C
Objective-C
2
star
24

Sideswipe

Network Image Library in Swift
Swift
2
star
25

common-crypto-spm

common crypto headers provided for the Swift Package Manager
Swift
2
star
26

bazaarvoice-challenge

Bazaarvoice programming exercise
Swift
1
star
27

goguid

generate GUID and UUIDs in go.
Go
1
star
28

daltoniam.com

portfolio website
CSS
1
star
29

bro

learn to write in a interpreter in C
C
1
star