Created
November 5, 2015 16:15
-
-
Save odrobnik/54b5f994e94f0f8268f0 to your computer and use it in GitHub Desktop.
Why does this work? what is the difference between AnyClass and T.Type? How could this be made more generic?
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
func classForName(name: String) -> AnyClass | |
{ | |
// build namespaced name | |
let namespacedName = "Module." + name | |
return NSClassFromString(namespacedName)! | |
} | |
func nameForType<T where T: Entity>(type: T.Type) -> String | |
{ | |
return NSStringFromClass(type).stringByReplacingOccurrencesOfString("Module.", withString: "") | |
} | |
if let expectedClass = self.classForName(entityName).self as? Entity.Type | |
{ | |
let result = expectedClass.init(dictionary: ...) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment