Skip to content

Instantly share code, notes, and snippets.

@T-Pham
Created April 24, 2019 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save T-Pham/21c9e68684b45bf78a5af5d01119fb80 to your computer and use it in GitHub Desktop.
Save T-Pham/21c9e68684b45bf78a5af5d01119fb80 to your computer and use it in GitHub Desktop.
DynamicObject.swift
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