I'm using PINCache (https://github.com/pinterest/PINCache) to cache some objects into my app. So, using objC it is perfect, but when I wanna cast with swift I had EXC_BAD_ACCESS
When I call objectForKey
- (id <NSCoding>)objectForKey:(NSString *)key;
And I have nothing cached for that key, but Swift understand that the object is an NSConding. So, if I have values into a key, I have no problems.
So, how can I cast this NSCoding result and compare with nil value. I only need to know if the object return from PINCache is nil (never cached).
I've already tried:
private func setupTrucks() {
let trucksCached: AnyObject? = PINDiskCache.sharedCache().objectForKey(TruckCache.key)
if let _truck = trucksCached as? [Truck] { //EXC_BAD_ACCESS here
print(_truck)
}
}
private func setupTrucks() {
let trucksCached = PINDiskCache.sharedCache().objectForKey(TruckCache.key) as [Truck] //EXC_BAD_ACCESS here
if trucksCached.count > 0 {
print(_truck)
}
}