How to connect my Swift app to my Parse Server?

限于喜欢 提交于 2019-12-06 17:16:37

问题


I'm working on connecting my Parse app to my Node.js Parse Server with the Swift language. In the documentation of Parse, I can see this code :

[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
   ...

   configuration.applicationId = @"YOUR_APP_ID";
   configuration.clientKey = @"YOUR_APP_CLIENT_KEY";
   configuration.server = @"http://localhost:1337/parse";

   ...

}]];

And since I use the Swift language, here is my configuration until now :

// Initialize Parse.
Parse.setApplicationId("APP_ID", clientKey: "CLIENT_KEY")

But how can I specify the server as in the Objective-C code ?

Thanks!


回答1:


Found the answer by myself, here is how to set a configuration (including the server URL) with Swift :

let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in
    ParseMutableClientConfiguration.applicationId = "APP_ID"
    ParseMutableClientConfiguration.clientKey = "CLIENT_KEY"
    ParseMutableClientConfiguration.server = "http://your_server.com:1337/parse"
})

Parse.initializeWithConfiguration(parseConfiguration)

Hope it will help someone else.




回答2:


Parse Server now has some good documentation going and it basically recommends @fraxool's solution with a little neater syntax:

let configuration = ParseClientConfiguration {
    $0.applicationId = "YOUR_APP_ID"
    $0.clientKey = ""
    $0.server = "http://localhost:1337/parse"
}
Parse.initializeWithConfiguration(configuration)



回答3:


Just to add the answer with Swift 3:

   let configuration = ParseClientConfiguration {
        $0.applicationId = "YOUR_APP_ID"
        $0.clientKey = ""
        $0.server = "http://localhost:1337/parse"
    }
    Parse.initialize(with: configuration)



回答4:


// Set App ID

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        let configuration = ParseClientConfiguration {
            $0.applicationId = PARSE_APP_KEY
            $0.clientKey = PARSE_CLIENT_KEY
            $0.server = "https://example.com"
        }
          Parse.initialize(with: configuration)

   return true
}


来源:https://stackoverflow.com/questions/35088410/how-to-connect-my-swift-app-to-my-parse-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!