I am trying to convert NSManagedObject
to NSDictionary
this is what I tried:
var keys:NSArray = order?.entity.attributesByName.keys
var dict:NSDictionary = order?.dictionaryWithValuesForKeys(keys)
But I get error:
LazyForwardCollection<MapCollectionView<Dictionary<NSObject,
AnyObject>, NSObject>>? is not convertible to NSArray.
What am I doing wrong here?
The keys
property of a dictionary returns a LazyForwardCollection
which has to be converted to a real array.
Another problem is that order
is apparently an optional, so it needs
to be unwrapped, e.g. with optional binding.
if let theOrder = order {
let keys = Array(theOrder.entity.attributesByName.keys)
let dict = theOrder.dictionaryWithValuesForKeys(keys)
} else {
// order is nil
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With