Git Product home page Git Product logo

agckimage's Introduction

AGCKImage is an easy to use framework to deal with CloudKit Image CKAsset.

Setup: Download the zip and drag the folder into your project!

Use: On any imageview pass the recordID of the record and the property key for the image asset

imageView.agCKImageAsset(post.recordID, assetKey: "image")

Other Functions To set CKAssets from Cloudkit: agCKImageAssetWithPlaceHolder(recordID:CKRecordID,assetKey:String,placeHolder:UIImage?) agCKImageAssetWithResetCacheForID(recordID:CKRecordID,assetKey:String) agCKImageAssetWithProgress(recordID:CKRecordID,assetKey:String,ckProgress:(progress:Double!,finished:Bool!)->Void) agCKImageAssetWithProgressWithResetCacheForID(recordID:CKRecordID,assetKey:String,ckProgress:(progress:Double!,finished:Bool!)->Void)

There are also methods for refresh cache for recordID,download with progress, and download with placeholders. The cache is automatically set up to clean files older than 2 days but this can be easily changed.

Using CloudKit this way allows for faster operations because you never have to include the assets in the desired keys. Also since CloudKit assets downloaded in the traditional methods are not guaranteed to persist or have the same names this simplifies the process.

To use this in the most effective way use CKQueryOperation when downloading your records. Use the .desiredKeys property and exclude the asset keys. This means speedier downloads. Then use the methods provided on the imageviews to fetch assets when needed. Example of CKQueryOperation if you are unfamiliar is..

     //This just gets the recordId which is all we need to load up some image assets using the provided framework.
      let predicate = NSPredicate(value: true)
    let query = CKQuery(recordType: "RecordType", predicate: predicate)
    let images: NSMutableArray = []
    
    let imageOperation = CKQueryOperation(query: query)
    imageOperation.desiredKeys = ["recordID"]
     imageOperation.qualityOfService = .UserInitiated
    imageOperation.queuePriority = .High
    imageOperation.recordFetchedBlock = {
        record in

        images.addObject(record)
    }

    imageOperation.queryCompletionBlock = {
        cursor,error in
        //reload your tableview,collectionview or whatever.  call on the main thread.
        dispatch_async(dispatch_get_main....blahaha{
        }
    }
    CKContainer.defaultContainer().publicCloudDatabase.addOperation(imageOperation)

Cheers.

Imgur

Also included is a download to cache in the backround.

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.