From dd2949ee180614a8fb7a29e217770718031b186d Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Thu, 11 May 2017 00:03:13 +0900 Subject: [PATCH] WIP: documentation --- Sources/Value.swift | 97 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/Sources/Value.swift b/Sources/Value.swift index d8cd2da..dd1a44d 100644 --- a/Sources/Value.swift +++ b/Sources/Value.swift @@ -36,24 +36,80 @@ infix operator .= : AssignmentPrecedence public extension DynamicObject where Self: CoreStoreObject { + /** + The containing type for value attributes. `Value` attributes support any type that conform to `ImportableAttributeType`. + ``` + class Animal: CoreStoreObject { + let species = Value.Required("species") + let nickname = Value.Optional("nickname") + } + ``` + */ public typealias Value = ValueContainer + + /** + The containing type for transformable attributes. `Transformable` attributes support types that conform to `NSCoding` and `NSCopying`. + ``` + class Animal: CoreStoreObject { + let ancestors = Transformable.Required("ancestors") + let descendants = Transformable.Optional("descendants") + } + ``` + */ public typealias Transformable = TransformableContainer } // MARK: - ValueContainer +/** + The containing type for value attributes. Use the `DynamicObject.Value` typealias instead for shorter syntax. + ``` + class Animal: CoreStoreObject { + let species = Value.Required("species") + let nickname = Value.Optional("nickname") + } + ``` + */ public enum ValueContainer { // MARK: - Required - + /** + The containing type for required value attributes. Any type that conform to `ImportableAttributeType` are supported. + ``` + class Animal: CoreStoreObject { + let species = Value.Required("species") + let nickname = Value.Optional("nickname") + } + ``` + */ public final class Required: AttributeProtocol { + /** + Assigns a value to the attribute. The operation + ``` + animal.species .= "Swift" + ``` + is equivalent to + ``` + animal.species.value = "Swift" + ``` + */ public static func .= (_ attribute: ValueContainer.Required, _ value: V) { attribute.value = value } + /** + Assigns a value to the attribute. The operation + ``` + animal.species .= anotherAnimal.species + ``` + is equivalent to + ``` + animal.species.value = anotherAnimal.species.value + ``` + */ public static func .= (_ attribute: ValueContainer.Required, _ attribute2: ValueContainer.Required) { attribute.value = attribute2.value @@ -149,18 +205,57 @@ public enum ValueContainer { // MARK: - Optional + /** + The containing type for optional value attributes. Any type that conform to `ImportableAttributeType` are supported. + ``` + class Animal: CoreStoreObject { + let species = Value.Required("species") + let nickname = Value.Optional("nickname") + } + ``` + */ public final class Optional: AttributeProtocol { + /** + Assigns a value to the attribute. The operation + ``` + animal.nickname .= "Taylor" + ``` + is equivalent to + ``` + animal.nickname.value = "Taylor" + ``` + */ public static func .= (_ attribute: ValueContainer.Optional, _ value: V?) { attribute.value = value } + /** + Assigns a value to the attribute. The operation + ``` + animal.nickname .= anotherAnimal.nickname + ``` + is equivalent to + ``` + animal.nickname.value = anotherAnimal.nickname.value + ``` + */ public static func .= (_ attribute: ValueContainer.Optional, _ attribute2: ValueContainer.Optional) { attribute.value = attribute2.value } + /** + Assigns a value to the attribute. The operation + ``` + animal.nickname .= anotherAnimal.nickname + ``` + is equivalent to + ``` + animal.nickname.value = anotherAnimal.nickname.value + ``` + */ public static func .= (_ attribute: ValueContainer.Optional, _ attribute2: ValueContainer.Required) { attribute.value = attribute2.value