An open API service indexing awesome lists of open source software.

https://github.com/nofelmahmood/cksrecordcontext

Interaction with CloudKit Records done right !
https://github.com/nofelmahmood/cksrecordcontext

ckrecord cloudkit cloudkit-databases swift

Last synced: 5 months ago
JSON representation

Interaction with CloudKit Records done right !

Awesome Lists containing this project

README

          

# CKSRecordContext

A dead simple way of `Fetching`, `Inserting`, `Modifying` and `Deleting` records from the CloudKit Databases.

## How To Use

A CKRecordContext object holds all the new records, any changes and deletions to them until you call `save()` on an instance of it. It only then conveys the changes to the CloudKit Database.

```swift
var cksRecordContext:CKSRecordContext = CKRecordContext(database: CKContainer.defaultContainer().privateCloudDatabase, recordZone: nil)
```
### Creating a new CKRecord

```swift
var ckRecord = cksRecordContext.insertNewCKRecord("NewRecordType")
```

### Modifying a CKRecord

Any CKRecords you create using methods of CKRecordContext are monitored by it.

### Deleting a CKRecord

```swift
var ckRecord = cksRecordContext.insertNewCKRecord("NewRecordType")
ckRecordContext.deleteRecord(record: ckRecord)
```

OR

```swift
var ckRecord = cksRecordContext.insertNewCKRecord("NewRecordType")
ckRecordContext.deleteRecord(recordID: ckRecord.recordID)
```

### Fetching Records

```swift
func fetchCKRecord(recordID:CKRecordID,completion:(record:CKRecord?,error:NSError!) ->())
func fetchCKRecords(recordType:String,predicate:NSPredicate,completion:(results:Array?,error:NSError!) ->())
func fetchCKRecords(recordType:String,predicate:NSPredicate,sortDescriptors:[NSSortDescriptor],completion:(results:Array?,error:NSError!) ->())
```

### Saving the Insertions, Modifications and Deletions to server.

Its a one liner !

```swift
cksRecordContext.save { (error) -> (Void) in
if error != nil
{
print("Saved Successfully")
}
}
```

## Getting Started
Check out the sample iOS demo app.

## Installation
`CocoaPods` is the recommended way of adding CKSRecordContext to your project.

You want to to add pod `'CKSRecordContext', '~> 0.5'` similar to the following to your Podfile:
```
target 'MyApp' do
pod 'CKSRecordContext', '~> 0.5'
end
```

Then run a `[sudo] pod install` inside your terminal, or from CocoaPods.app.

## Credits
CKSRecordContext was created by [Nofel Mahmood](http://twitter.com/NofelMahmood)

## Contact
Follow Nofel Mahmood on [Twitter](http://twitter.com/NofelMahmood) and [GitHub](http://github.com/nofelmahmood) or email him at nofelmehmood@gmail.com

## License
CKSRecordContext is available under the MIT license. See the LICENSE file for more info.