Created
April 24, 2019 22:36
-
-
Save T-Pham/21c9e68684b45bf78a5af5d01119fb80 to your computer and use it in GitHub Desktop.
DynamicObject.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@dynamicMemberLookup | |
class DynamicObject: NSObject { | |
subscript<T>(dynamicMember member: String) -> T? { | |
get { | |
return objc_getAssociatedObject(self, member) as? T | |
} | |
set { | |
objc_setAssociatedObject(self, member, newValue, .OBJC_ASSOCIATION_RETAIN) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment