Skip to content

Commit

Permalink
Added location sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Vermeer, Edwin authored and Vermeer, Edwin committed Sep 16, 2017
1 parent 3cccc4b commit 2940137
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
4 changes: 2 additions & 2 deletions AppMessage/AppMessage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "AppMessage/AppMessage-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -570,7 +570,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "AppMessage/AppMessage-Bridging-Header.h";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion AppMessage/AppMessage/Controlers/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class ChatViewController: JSQMessagesViewController, UIActionSheetDelegate, Uzys
} else {
cell.textView!.textColor = UIColor.white
}
cell.textView!.linkTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue : cell.textView!.textColor!, NSAttributedStringKey.underlineStyle.rawValue : NSUnderlineStyle.styleSingle.rawValue]
//cell.textView!.linkTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue : cell.textView!.textColor!, NSAttributedStringKey.underlineStyle.rawValue : NSUnderlineStyle.styleSingle.rawValue]
}
return cell
}
Expand Down
4 changes: 2 additions & 2 deletions AppMessage/AppMessage/Controlers/LeftMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ class LeftMenuViewController: UIViewController, UITableViewDataSource, UITableVi
// ------------------------------------------------------------------------

func connectToNews(_ retryCount: Double = 1) {

let loc: CLLocation! = nil
EVCloudData.publicDB.connect(
News(), predicate: NSPredicate(value: true), orderBy: Ascending(field: "Subject").Descending("creationDate"), filterId: "News_All", configureNotificationInfo: { notificationInfo in
News(), predicate: NSPredicate(value: true), orderBy: Distance(field: "", relativeLocation: loc).Ascending("Subject").Descending("creationDate"), filterId: "News_All", configureNotificationInfo: { notificationInfo in
//notificationInfo.alertBody = "News update"
notificationInfo.shouldSendContentAvailable = true // is already the default
notificationInfo.alertLocalizationKey = "News: %1$@"
Expand Down
2 changes: 1 addition & 1 deletion EVCloudKitDao.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "EVCloudKitDao"
s.version = "3.3.3"
s.version = "3.5.0"
s.summary = "iOS: Simplified access to Apple’s CloudKit"
s.description = "Simplified access to Apple’s CloudKit using reflection and generics"

Expand Down
24 changes: 23 additions & 1 deletion Source/EVSort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//

import Foundation
import CoreLocation
import CloudKit

/**
Enum that will be used to specify the order
Expand All @@ -23,6 +25,7 @@ open class OrderBy {
var field: String = ""
var direction: SortDirection = .descending
var parent: OrderBy?
var sortDescriptor: NSSortDescriptor? = nil

/**
Convenience init for creating an order object with all the parameters
Expand All @@ -36,6 +39,12 @@ open class OrderBy {
self.field = field
self.direction = direction
self.parent = parent
self.sortDescriptor = NSSortDescriptor(key: field, ascending: (direction == .ascending))
}

public convenience init(sortDescriptor: NSSortDescriptor, parent: OrderBy? = nil) {
self.init()
self.sortDescriptor = sortDescriptor
}

/**
Expand All @@ -60,14 +69,20 @@ open class OrderBy {
return OrderBy(field: field, parent: self, direction: .descending)
}

open func Distance(_ field: String, relativeLocation: CLLocation) -> OrderBy {
return OrderBy(sortDescriptor: CKLocationSortDescriptor(key: field, relativeLocation: relativeLocation), parent: self)
}

/**
Build up an array of sortDescriptors
- returns: The array of sortDescriptors
*/
open func sortDescriptors() -> [NSSortDescriptor] {
var result: [NSSortDescriptor] = parent?.sortDescriptors() ?? []
result.append( NSSortDescriptor(key: field, ascending: (direction == .ascending)))
if let sort = self.sortDescriptor {
result.append(sort)
}
return result
}
}
Expand Down Expand Up @@ -95,3 +110,10 @@ open class Descending: OrderBy {
self.init(field: field, parent: nil, direction: .descending)
}
}

// Just here so that we can use a nice name while ordering.
open class Distance: OrderBy {
public convenience required init(field: String, relativeLocation: CLLocation) {
self.init(sortDescriptor: CKLocationSortDescriptor(key: field, relativeLocation: relativeLocation), parent: nil)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7F29764D1BB93D6A0074C85A"
BuildableName = "OSXTest.xctest"
BlueprintName = "OSXTest"
ReferencedContainer = "container:UnitTests.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand All @@ -23,19 +40,38 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7F29764D1BB93D6A0074C85A"
BuildableName = "OSXTest.xctest"
BlueprintName = "OSXTest"
ReferencedContainer = "container:UnitTests.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7F29764D1BB93D6A0074C85A"
BuildableName = "OSXTest.xctest"
BlueprintName = "OSXTest"
ReferencedContainer = "container:UnitTests.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand All @@ -45,6 +81,15 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7F29764D1BB93D6A0074C85A"
BuildableName = "OSXTest.xctest"
BlueprintName = "OSXTest"
ReferencedContainer = "container:UnitTests.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down

0 comments on commit 2940137

Please sign in to comment.