16

我正在使用 Swift 语言将我的 Parse 应用程序连接到我的 Node.js Parse Server。在 Parse 的文档中,我可以看到以下代码:

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

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

   ...

}]];

由于我使用的是 Swift 语言,所以这是我到现在为止的配置:

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

但是我怎样才能像在 Objective-C 代码中那样指定服务器呢?

谢谢!

4

4 回答 4

28

我自己找到了答案,这里是如何使用 Swift 设置配置(包括服务器 URL):

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)

希望它会帮助别人。

于 2016-01-29T16:55:30.863 回答
3

Parse Server 现在有一些很好的文档,它基本上推荐@fraxool 的解决方案,语法更简洁:

let configuration = ParseClientConfiguration {
    $0.applicationId = "YOUR_APP_ID"
    $0.clientKey = ""
    $0.server = "http://localhost:1337/parse"
}
Parse.initializeWithConfiguration(configuration)
于 2016-02-23T21:14:20.370 回答
2

只需使用 Swift 3 添加答案:

   let configuration = ParseClientConfiguration {
        $0.applicationId = "YOUR_APP_ID"
        $0.clientKey = ""
        $0.server = "http://localhost:1337/parse"
    }
    Parse.initialize(with: configuration)
于 2016-12-04T18:13:05.357 回答
-1

//设置应用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
}
于 2018-01-07T16:21:38.817 回答