ObjectiveCSupport+Sync.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. import Realm
  19. /**
  20. :nodoc:
  21. **/
  22. public extension ObjectiveCSupport {
  23. /// Convert a `SyncConfiguration` to a `RLMSyncConfiguration`.
  24. static func convert(object: SyncConfiguration) -> RLMSyncConfiguration {
  25. return object.asConfig()
  26. }
  27. /// Convert a `RLMSyncConfiguration` to a `SyncConfiguration`.
  28. static func convert(object: RLMSyncConfiguration) -> SyncConfiguration {
  29. return SyncConfiguration(config: object)
  30. }
  31. /// Convert a `Credentials` to a `RLMCredentials`
  32. static func convert(object: Credentials) -> RLMCredentials {
  33. switch object {
  34. case .facebook(let accessToken):
  35. return RLMCredentials(facebookToken: accessToken)
  36. case .google(let serverAuthCode):
  37. return RLMCredentials(googleAuthCode: serverAuthCode)
  38. case .googleId(let token):
  39. return RLMCredentials(googleIdToken: token)
  40. case .apple(let idToken):
  41. return RLMCredentials(appleToken: idToken)
  42. case .emailPassword(let email, let password):
  43. return RLMCredentials(email: email, password: password)
  44. case .jwt(let token):
  45. return RLMCredentials(jwt: token)
  46. case .function(let payload):
  47. return RLMCredentials(functionPayload: ObjectiveCSupport.convert(object: AnyBSON(payload))! as! [String: RLMBSON])
  48. case .userAPIKey(let APIKey):
  49. return RLMCredentials(userAPIKey: APIKey)
  50. case .serverAPIKey(let serverAPIKey):
  51. return RLMCredentials(serverAPIKey: serverAPIKey)
  52. case .anonymous:
  53. return RLMCredentials.anonymous()
  54. }
  55. }
  56. }