Browse Source

Make AlamofireExtension More Public (#3075)

* Make AlamofireExtension more public, add @dynamicMemberLookup.

* Add inline docs.
Jon Shier 6 years ago
parent
commit
f0e7cac1a6
1 changed files with 13 additions and 3 deletions
  1. 13 3
      Source/AlamofireExtended.swift

+ 13 - 3
Source/AlamofireExtended.swift

@@ -23,13 +23,23 @@
 //
 
 /// Type that acts as a generic extension point for all `AlamofireExtended` types.
+@dynamicMemberLookup
 public struct AlamofireExtension<ExtendedType> {
-    /// Stores the type or metatype of any extended type.
-    let type: ExtendedType
+    /// Stores the type or meta-type of any extended type.
+    public private(set) var type: ExtendedType
 
-    init(_ type: ExtendedType) {
+    /// Create an instance from the provided value.
+    ///
+    /// - Parameter type: Instance being extended.
+    public init(_ type: ExtendedType) {
         self.type = type
     }
+
+    /// Get and set properties through a `WritableKeyPath` subscript for `@dynamicMemberLookup`.
+    public subscript<Property>(dynamicMember keyPath: WritableKeyPath<ExtendedType, Property>) -> Property {
+        get { type[keyPath: keyPath] }
+        set { type[keyPath: keyPath] = newValue }
+    }
 }
 
 /// Protocol describing the `af` extension points for Alamofire extended types.