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 !
- Host: GitHub
- URL: https://github.com/nofelmahmood/cksrecordcontext
- Owner: nofelmahmood
- License: mit
- Created: 2015-06-21T11:37:09.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-23T12:42:30.000Z (almost 11 years ago)
- Last Synced: 2025-03-30T00:31:44.590Z (about 1 year ago)
- Topics: ckrecord, cloudkit, cloudkit-databases, swift
- Language: Swift
- Homepage: https://medium.com/p/cloudkit-in-context-1efd6ec23ed1
- Size: 363 KB
- Stars: 21
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.