Property.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2014 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 Foundation
  19. import Realm
  20. /**
  21. `Property` instances represent properties managed by a Realm in the context of an object schema. Such properties may be
  22. persisted to a Realm file or computed from other data in the Realm.
  23. When using Realm, property instances allow performing migrations and introspecting the database's schema.
  24. Property instances map to columns in the core database.
  25. */
  26. public struct Property: CustomStringConvertible {
  27. // MARK: Properties
  28. internal let rlmProperty: RLMProperty
  29. /// The name of the property.
  30. public var name: String { return rlmProperty.name }
  31. /// The type of the property.
  32. public var type: PropertyType { return rlmProperty.type }
  33. /// Indicates whether this property is an array of the property type.
  34. public var isArray: Bool { return rlmProperty.array }
  35. /// Indicates whether this property is indexed.
  36. public var isIndexed: Bool { return rlmProperty.indexed }
  37. /// Indicates whether this property is optional. (Note that certain numeric types must be wrapped in a
  38. /// `RealmOptional` instance in order to be declared as optional.)
  39. public var isOptional: Bool { return rlmProperty.optional }
  40. /// For `Object` and `List` properties, the name of the class of object stored in the property.
  41. public var objectClassName: String? { return rlmProperty.objectClassName }
  42. /// A human-readable description of the property object.
  43. public var description: String { return rlmProperty.description }
  44. // MARK: Initializers
  45. internal init(_ rlmProperty: RLMProperty) {
  46. self.rlmProperty = rlmProperty
  47. }
  48. }
  49. // MARK: Equatable
  50. extension Property: Equatable {
  51. /// Returns whether the two properties are equal.
  52. public static func == (lhs: Property, rhs: Property) -> Bool {
  53. return lhs.rlmProperty.isEqual(to: rhs.rlmProperty)
  54. }
  55. }