Skip to content

Commit 566f68e

Browse files
committed
refactor to configureParse
1 parent 7d16328 commit 566f68e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ A sample app, [CareKitSample-ParseCareKit](https://github.com/netreconlab/CareKi
4141
<img src="https://user-images.githubusercontent.com/8621344/99022137-1ec7ca80-2530-11eb-897c-ace7c70536f2.png" width="300"> <img src="https://user-images.githubusercontent.com/8621344/99022190-3bfc9900-2530-11eb-8ad1-c1e8ba2e7f55.png" width="300">
4242

4343
### ParseCareKit.plist with server connection information
44-
ParseCareKit comes with a helper method, [PCKUtility.setupServer()](https://github.com/netreconlab/ParseCareKit/blob/4912bf7677511d148b52d03146c31cc428a83454/ParseCareKit/PCKUtility.swift#L14) that easily helps apps connect to your parse-server. To leverage the helper method, copy the [ParseCareKit.plist](https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/main/OCKSample/Supporting%20Files/ParseCareKit.plist) file your "Supporting Files" folder in your Xcode project. Be sure to change `ApplicationID` and `Server` to the correct values for your server. Simply add the following inside `didFinishLaunchingWithOptions` in `AppDelegate.swift`:
44+
ParseCareKit comes with a helper method, [PCKUtility.configureParse()](https://github.com/netreconlab/ParseCareKit/blob/4912bf7677511d148b52d03146c31cc428a83454/ParseCareKit/PCKUtility.swift#L14) that easily helps apps connect to your parse-server. To leverage the helper method, copy the [ParseCareKit.plist](https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/main/OCKSample/Supporting%20Files/ParseCareKit.plist) file your "Supporting Files" folder in your Xcode project. Be sure to change `ApplicationID` and `Server` to the correct values for your server. Simply add the following inside `didFinishLaunchingWithOptions` in `AppDelegate.swift`:
4545

4646
```swift
4747
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
4848

4949
//Pulls from ParseCareKit.plist to connect to server
50-
PCKUtility.setupServer()
50+
PCKUtility.configureParse()
5151

5252
//If you need certificate pinning:
53-
PCKUtility.setupServer { (challenge, completionHandler) in
53+
PCKUtility.configureParse { (challenge, completionHandler) in
5454
//Return how you want to handle the challenge. See docs for more information.
5555
completionHandler(.performDefaultHandling, nil)
5656
}

Sources/ParseCareKit/PCKUtility.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PCKUtility {
1919
var propertyListFormat = PropertyListSerialization.PropertyListFormat.xml
2020
guard let path = Bundle.main.path(forResource: fileName, ofType: "plist"),
2121
let xml = FileManager.default.contents(atPath: path) else {
22-
fatalError("Error in ParseCareKit.setupServer(). Cannot find ParseCareKit.plist in this project")
22+
fatalError("Error in ParseCareKit.configureParse(). Cannot find ParseCareKit.plist in this project")
2323
}
2424

2525
return try PropertyListSerialization.propertyList(from: xml,
@@ -29,7 +29,7 @@ public class PCKUtility {
2929
}
3030

3131
/**
32-
Setup a connection to Parse Server based on a ParseCareKit.plist file.
32+
Configure the client to connect to a Parse Server based on a ParseCareKit.plist file.
3333

3434
The key/values supported in the file are a dictionary named `ParseClientConfiguration`:
3535
- Server - (String) The server URL to connect to Parse Server.
@@ -45,10 +45,10 @@ public class PCKUtility {
4545
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
4646
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
4747
*/
48-
public class func setupServer(fileName: String = "ParseCareKit",
49-
authentication: ((URLAuthenticationChallenge,
50-
(URLSession.AuthChallengeDisposition,
51-
URLCredential?) -> Void) -> Void)? = nil) async throws {
48+
public class func configureParse(fileName: String = "ParseCareKit",
49+
authentication: ((URLAuthenticationChallenge,
50+
(URLSession.AuthChallengeDisposition,
51+
URLCredential?) -> Void) -> Void)? = nil) async throws {
5252
var plistConfiguration: [String: AnyObject]
5353
var clientKey: String?
5454
var liveQueryURL: URL?
@@ -57,13 +57,13 @@ public class PCKUtility {
5757
do {
5858
plistConfiguration = try Self.getPlistConfiguration(fileName: fileName)
5959
} catch {
60-
fatalError("Error in ParseCareKit.setupServer(). Could not serialize plist. \(error)")
60+
fatalError("Error in ParseCareKit.configureParse(). Could not serialize plist. \(error)")
6161
}
6262

6363
guard let appID = plistConfiguration["ApplicationID"] as? String,
6464
let server = plistConfiguration["Server"] as? String,
6565
let serverURL = URL(string: server) else {
66-
fatalError("Error in ParseCareKit.setupServer(). Missing keys in \(plistConfiguration)")
66+
fatalError("Error in ParseCareKit.configureParse(). Missing keys in \(plistConfiguration)")
6767
}
6868

6969
if let client = plistConfiguration["ClientKey"] as? String {
@@ -109,7 +109,7 @@ public class PCKUtility {
109109
do {
110110
plistConfiguration = try Self.getPlistConfiguration(fileName: fileName)
111111
} catch {
112-
fatalError("Error in ParseCareKit.setupServer(). Could not serialize plist. \(error)")
112+
fatalError("Error in ParseCareKit.configureParse(). Could not serialize plist. \(error)")
113113
}
114114

115115
if let keychainAccessGroup = plistConfiguration["AccessGroup"] as? String {

Tests/ParseCareKitTests/UtilityTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class UtilityTests: XCTestCase {
2121
PCKUtility.removeCache()
2222
}
2323

24-
func testSetupServer() async throws {
25-
try await PCKUtility.setupServer { (_, completionHandler) in
24+
func testConfigureParse() async throws {
25+
try await PCKUtility.configureParse { (_, completionHandler) in
2626
completionHandler(.performDefaultHandling, nil)
2727
}
2828
XCTAssertEqual(ParseSwift.configuration.applicationId, "3B5FD9DA-C278-4582-90DC-101C08E7FC98")

0 commit comments

Comments
 (0)