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