Skip to content

Commit 43f603f

Browse files
authored
Merge pull request #8 from olmps/feature/spm
Swift Package Manager support
2 parents 8982651 + 5f2f6ab commit 43f603f

File tree

6 files changed

+123
-43
lines changed

6 files changed

+123
-43
lines changed

NestedCloudKitCodable.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
630DDFD824F5C13300537AD5 /* NestedCloudKitCodableMacOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NestedCloudKitCodableMacOS.entitlements; sourceTree = "<group>"; };
162162
635A0E8B24F562C4002BC7AD /* NestedCloudKitCodableTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NestedCloudKitCodableTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
163163
635A0EF824F56516002BC7AD /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
164+
63658A6525CC31FE0000C747 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
164165
6375386324F5347D0093936D /* NestedCloudKitCodableWatch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NestedCloudKitCodableWatch.app; sourceTree = BUILT_PRODUCTS_DIR; };
165166
6375386624F5347D0093936D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Interface.storyboard; sourceTree = "<group>"; };
166167
6375386824F5347E0093936D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -288,6 +289,7 @@
288289
607FACC71AFB9204008FA782 = {
289290
isa = PBXGroup;
290291
children = (
292+
63658A6525CC31FE0000C747 /* Package.swift */,
291293
63A249B324F567E9008C8C56 /* Source */,
292294
63CDFCF524F5477900535338 /* NestedCloudKitCodable_Example.entitlements */,
293295
63CDFCE424F53D3D00535338 /* Shared */,

NestedCloudKitCodable.xcodeproj/xcshareddata/xcschemes/NestedCloudKitCodableWatch (Notification).xcscheme

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,16 @@
5656
allowLocationSimulation = "YES"
5757
launchAutomaticallySubstyle = "8"
5858
notificationPayloadFile = "NestedCloudKitCodableWatch Extension/PushNotificationPayload.apns">
59-
<RemoteRunnable
60-
runnableDebuggingMode = "2"
61-
BundleIdentifier = "com.apple.Carousel"
62-
RemotePath = "/NestedCloudKitCodable_Example">
59+
<BuildableProductRunnable
60+
runnableDebuggingMode = "0">
6361
<BuildableReference
6462
BuildableIdentifier = "primary"
6563
BlueprintIdentifier = "6375386224F5347D0093936D"
6664
BuildableName = "NestedCloudKitCodableWatch.app"
6765
BlueprintName = "NestedCloudKitCodableWatch"
6866
ReferencedContainer = "container:NestedCloudKitCodable.xcodeproj">
6967
</BuildableReference>
70-
</RemoteRunnable>
68+
</BuildableProductRunnable>
7169
</LaunchAction>
7270
<ProfileAction
7371
buildConfiguration = "Release"
@@ -77,27 +75,16 @@
7775
debugDocumentVersioning = "YES"
7876
launchAutomaticallySubstyle = "8"
7977
notificationPayloadFile = "NestedCloudKitCodableWatch Extension/PushNotificationPayload.apns">
80-
<RemoteRunnable
81-
runnableDebuggingMode = "2"
82-
BundleIdentifier = "com.apple.Carousel"
83-
RemotePath = "/NestedCloudKitCodable_Example">
78+
<BuildableProductRunnable
79+
runnableDebuggingMode = "0">
8480
<BuildableReference
8581
BuildableIdentifier = "primary"
8682
BlueprintIdentifier = "6375386224F5347D0093936D"
8783
BuildableName = "NestedCloudKitCodableWatch.app"
8884
BlueprintName = "NestedCloudKitCodableWatch"
8985
ReferencedContainer = "container:NestedCloudKitCodable.xcodeproj">
9086
</BuildableReference>
91-
</RemoteRunnable>
92-
<MacroExpansion>
93-
<BuildableReference
94-
BuildableIdentifier = "primary"
95-
BlueprintIdentifier = "6375386224F5347D0093936D"
96-
BuildableName = "NestedCloudKitCodableWatch.app"
97-
BlueprintName = "NestedCloudKitCodableWatch"
98-
ReferencedContainer = "container:NestedCloudKitCodable.xcodeproj">
99-
</BuildableReference>
100-
</MacroExpansion>
87+
</BuildableProductRunnable>
10188
</ProfileAction>
10289
<AnalyzeAction
10390
buildConfiguration = "Debug">

NestedCloudKitCodable/Base.lproj/Main.storyboard

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3-
<device id="retina4_7" orientation="portrait">
4-
<adaptation id="fullscreen"/>
5-
</device>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3+
<device id="retina4_7" orientation="portrait" appearance="light"/>
64
<dependencies>
75
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
97
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
108
</dependencies>
119
<scenes>
@@ -20,11 +18,54 @@
2018
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
2119
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2220
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
21+
<subviews>
22+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="46" translatesAutoresizingMaskIntoConstraints="NO" id="V4e-g8-jiG">
23+
<rect key="frame" x="135.5" y="280.5" width="104" height="106"/>
24+
<subviews>
25+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AXo-LC-48C">
26+
<rect key="frame" x="0.0" y="0.0" width="104" height="30"/>
27+
<state key="normal" title="Encode School"/>
28+
<connections>
29+
<action selector="encodeTapped:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="jlj-KU-QRw"/>
30+
</connections>
31+
</button>
32+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JiC-5R-2CI">
33+
<rect key="frame" x="0.0" y="76" width="104" height="30"/>
34+
<state key="normal" title="Decode School"/>
35+
<connections>
36+
<action selector="decodeTapped:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Dij-fo-U3D"/>
37+
</connections>
38+
</button>
39+
</subviews>
40+
</stackView>
41+
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" hidesWhenStopped="YES" style="large" translatesAutoresizingMaskIntoConstraints="NO" id="Eww-Al-f3S">
42+
<rect key="frame" x="177" y="202" width="20" height="20"/>
43+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
44+
</activityIndicatorView>
45+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Result:" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7dX-sG-QHO">
46+
<rect key="frame" x="36" y="406.5" width="303" height="20.5"/>
47+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
48+
<nil key="textColor"/>
49+
<nil key="highlightedColor"/>
50+
</label>
51+
</subviews>
2352
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
53+
<constraints>
54+
<constraint firstItem="7dX-sG-QHO" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="20" id="3bc-Ql-8bV"/>
55+
<constraint firstItem="V4e-g8-jiG" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="BrR-68-BGl"/>
56+
<constraint firstItem="V4e-g8-jiG" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="Gi6-5A-yM4"/>
57+
<constraint firstAttribute="trailingMargin" secondItem="7dX-sG-QHO" secondAttribute="trailing" constant="20" id="YKG-Gd-pCz"/>
58+
<constraint firstItem="7dX-sG-QHO" firstAttribute="top" secondItem="V4e-g8-jiG" secondAttribute="bottom" constant="20" id="fpC-hI-TzX"/>
59+
</constraints>
2460
</view>
61+
<connections>
62+
<outlet property="activityIndicator" destination="Eww-Al-f3S" id="KPu-yj-ogP"/>
63+
<outlet property="resultLabel" destination="7dX-sG-QHO" id="oIP-0h-4KP"/>
64+
</connections>
2565
</viewController>
2666
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
2767
</objects>
68+
<point key="canvasLocation" x="-295" y="134"/>
2869
</scene>
2970
</scenes>
3071
</document>

NestedCloudKitCodable/ViewController.swift

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import NestedCloudKitCodable
1212

1313
class ViewController: UIViewController {
1414

15+
@IBOutlet private var resultLabel: UILabel!
16+
@IBOutlet private var activityIndicator: UIActivityIndicatorView!
17+
18+
private var schoolRecord: CKRecord?
19+
1520
private var director: Person {
1621
return Person(name: "Director", birthDate: Date())
1722
}
@@ -37,47 +42,74 @@ class ViewController: UIViewController {
3742
return [book1, book2]
3843
}
3944

40-
private var database: CKDatabase {
41-
return CKContainer(identifier: "iCloud.com.nestedCloudKitCodable.Container").publicCloudDatabase
42-
}
43-
44-
override func viewDidLoad() {
45-
super.viewDidLoad()
46-
45+
private var school: School {
4746
var schoolObject = School()
4847
schoolObject.name = "School Name"
4948
schoolObject.location = CLLocation(latitude: 37.331274, longitude: -122.030397)
5049
schoolObject.students = students
5150
schoolObject.director = director
5251
schoolObject.books = books
5352

53+
return schoolObject
54+
}
55+
56+
private var database: CKDatabase {
57+
return CKContainer(identifier: "iCloud.com.nestedCloudKitCodable.Container").publicCloudDatabase
58+
}
59+
60+
@IBAction private func encodeTapped(_ sender: UIButton) {
61+
activityIndicator.isHidden = false
62+
activityIndicator.startAnimating()
63+
resultLabel.text = "Loading..."
64+
5465
do {
55-
let encodedRecords = try CKRecordEncoder().encode(schoolObject)
66+
let encodedRecords = try CKRecordEncoder().encode(school)
67+
schoolRecord = encodedRecords.last
5668

5769
let saveOperator = CKModifyRecordsOperation(recordsToSave: encodedRecords)
5870
saveOperator.modifyRecordsCompletionBlock = { (records, recordsIDs, error) in
59-
if let error = error {
60-
print(error)
61-
} else {
62-
self.decodeSchool(encodedRecords.last!)
71+
DispatchQueue.main.async {
72+
self.activityIndicator.stopAnimating()
73+
74+
if let error = error {
75+
print(error)
76+
self.resultLabel.text = "Error: \(error.localizedDescription)"
77+
} else {
78+
self.resultLabel.text = "Successfully encoded school object!"
79+
}
6380
}
6481
}
6582

6683
database.add(saveOperator)
6784
} catch let error {
6885
let formattedError = error as! CKCodableError //swiftlint:disable:this force_cast
69-
print(formattedError)
86+
resultLabel.text = "Error: \(formattedError.localizedDescription)"
7087
}
7188
}
7289

73-
private func decodeSchool(_ schoolRecord: CKRecord) {
90+
@IBAction private func decodeTapped(_ sender: UIButton) {
91+
guard let schoolRecord = schoolRecord else {
92+
resultLabel.text = "Please encode the object first"
93+
return
94+
}
95+
96+
activityIndicator.isHidden = false
97+
activityIndicator.startAnimating()
98+
resultLabel.text = "Loading..."
99+
74100
CKRecordDecoder().decode(School.self,
75101
from: schoolRecord,
76102
referenceDatabase: database) { (decodedSchool, error) in
77-
if let error = error {
78-
print(error)
79-
} else if let decodedSchool = decodedSchool {
80-
print(decodedSchool)
103+
DispatchQueue.main.async {
104+
self.activityIndicator.stopAnimating()
105+
106+
if let error = error {
107+
print(error)
108+
self.resultLabel.text = "Error: \(error.localizedDescription)"
109+
} else if let decodedSchool = decodedSchool {
110+
self.resultLabel.text = "Successfully encoded school object!"
111+
print(decodedSchool)
112+
}
81113
}
82114
}
83115
}

Package.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// swift-tools-version:5.0
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "NestedCloudKitCodable",
6+
platforms: [
7+
.macOS(.v10_13),
8+
.iOS(.v10),
9+
.tvOS(.v11),
10+
.watchOS(.v3),
11+
],
12+
products: [
13+
.library(name: "NestedCloudKitCodable", targets: ["NestedCKCodable"])
14+
],
15+
targets: [
16+
.target(name: "NestedCKCodable", path: "./Source")
17+
]
18+
)

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ SPEC CHECKSUMS:
2020

2121
PODFILE CHECKSUM: 2ffe4c6d25cbfb6b22eb4b0a78b0a2359a4bb4f2
2222

23-
COCOAPODS: 1.9.3
23+
COCOAPODS: 1.10.0

0 commit comments

Comments
 (0)