Skip to content

Commit

Permalink
sort order fix
Browse files Browse the repository at this point in the history
  • Loading branch information
evermeer committed Apr 2, 2016
1 parent f54cd47 commit 0ee2bb0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
3 changes: 2 additions & 1 deletion AppMessage/AppMessage/CloudKit/EVCloudData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ public class EVCloudData: NSObject {
if existingItem != nil {
EVLog("Update object for filter \(filter)")
EVReflection.setPropertiesfromDictionary(item.toDictionary(), anyObject: data[filter]![itemID!])
data[filter] = (data[filter]! as NSArray).sortedArrayUsingDescriptors(sortOrders[filter]!.sortDescriptors()) as? [EVCloudKitDataObject]
NSOperationQueue.mainQueue().addOperationWithBlock {
(self.updateHandlers[filter]!)(item: item, dataIndex:itemID!)
(self.dataChangedHandlers[filter]!)()
Expand All @@ -457,14 +458,14 @@ public class EVCloudData: NSObject {
} else {
EVLog("Insert object for filter \(filter)")
data[filter]!.insert(item, atIndex: 0)
data[filter] = (data[filter]! as NSArray).sortedArrayUsingDescriptors(sortOrders[filter]!.sortDescriptors()) as? [EVCloudKitDataObject]
NSOperationQueue.mainQueue().addOperationWithBlock {
(self.insertedHandlers[filter]!)(item: item)
(self.dataChangedHandlers[filter]!)()
self.postDataInsertedNotification(filter, item: item)
}
dataIsUpdated(filter)
}
data[filter] = (data[filter]! as NSArray).sortedArrayUsingDescriptors(sortOrders[filter]!.sortDescriptors()) as? [EVCloudKitDataObject]
} else { // An update of a field that is used in the predicate could trigger a delete from that set.
EVLog("Object not for filter \(filter)")
if itemID != nil {
Expand Down
46 changes: 35 additions & 11 deletions AppMessage/AppMessage/CloudKit/EVCloudKitDao.swift
Original file line number Diff line number Diff line change
Expand Up @@ -558,19 +558,43 @@ public class EVCloudKitDao {
- parameter errorHandler: The function that will be called when there was an error
:return: No return value
*/
public func getItem(recordId: String, completionHandler: (result: EVCloudKitDataObject) -> Void, errorHandler:((error: NSError) -> Void)? = nil) {
database.fetchRecordWithID(CKRecordID(recordName: recordId), completionHandler: {record, error in
self.handleCallback(error, errorHandler: errorHandler, completionHandler: {
if let parsed = self.fromCKRecord(record) {
completionHandler(result: parsed);
} else {
if let handler = errorHandler {
let error = NSError(domain: "EVCloudKitDao", code: 1, userInfo:nil)
handler(error: error)
}
public func getItem(recordId: String, completionHandler: (result: EVCloudKitDataObject) -> Void, errorHandler:((error: NSError) -> Void)? = nil) -> CKFetchRecordsOperation {
let operation = CKFetchRecordsOperation(recordIDs: [CKRecordID(recordName: recordId)])
operation.qualityOfService = .UserInitiated
operation.queuePriority = .VeryHigh
operation.perRecordCompletionBlock = { record, id, error in
if let parsed = self.fromCKRecord(record) {
completionHandler(result: parsed);
} else {
if let handler = errorHandler {
let error = NSError(domain: "EVCloudKitDao", code: 1, userInfo:nil)
handler(error: error)
}
}
}
database.addOperation(operation)
return operation
}

/**
Get multiple Items for their recordIds
- parameter recordIds: The CloudKit record ids that we want to get.
- parameter completionHandler: The function that will be called with the objects that we aksed for
- parameter errorHandler: The function that will be called when there was an error
:return: No return value
*/
public func getItems(recordIds: [String], completionHandler: (results: [EVCloudKitDataObject]) -> Void, errorHandler:((error: NSError) -> Void)? = nil) -> CKFetchRecordsOperation {
let operation = CKFetchRecordsOperation(recordIDs: recordIds.map({CKRecordID(recordName: $0)}))
operation.qualityOfService = .UserInitiated
operation.queuePriority = .VeryHigh
operation.fetchRecordsCompletionBlock = { result, error in
self.handleCallback(error, errorHandler: errorHandler, completionHandler: {
let r: [EVCloudKitDataObject] = result!.map({ (key, value) in self.fromCKRecord(value)!})
completionHandler(results: r)
})
})
}
database.addOperation(operation)
return operation
}

/**
Expand Down
2 changes: 1 addition & 1 deletion EVCloudKitDao.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Pod::Spec.new do |s|
#

s.name = "EVCloudKitDao"
s.version = "2.17.0"
s.version = "2.19.0"
s.summary = "iOS: Simplified access to Apple’s CloudKit"

s.description = "Simplified access to Apple’s CloudKit using reflection and generics"
Expand Down

0 comments on commit 0ee2bb0

Please sign in to comment.