Last active
March 17, 2017 15:28
-
-
Save delebedev/165818fb60f28312096e21462e0aee76 to your computer and use it in GitHub Desktop.
Swift CoreData craziness
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
// Class Keyword: NSManagedObject is defined in objective-c (not sure if it matters) | |
// .keywords is CoreData to-many relationship pointing to "Keyword" objects. | |
// How do I convert .keywords to [Keyword]? | |
po type(of: keywords) | |
_NSFaultingMutableOrderedSet | |
po keywords is NSOrderedSet | |
true | |
// NSOrderedSet does not store type information | |
po type(of: keywords.array) | |
Swift.Array<Any> | |
// well this is expected | |
po keywords.array is [Keyword] | |
false | |
// let's introspect an object | |
expr let $k = keywords.array[0] | |
//oh | |
po $k is Keyword | |
false | |
//oh | |
po type(of: $k) | |
NSManagedObject_Keyword_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
keywords.array as [Keyword]
should work. Thanks to magic inside compiler for bridging from objc to swift.If not working -
keywords.array.flatMap { $0 as? Keyword }