1
我有executeFetchRequest一些問題斯威夫特:executeFetchRequest:無法將類型的價值 '任何對象'
import UIKit
import CoreData
class BeaconDB: NSObject {
var addStatus: BeaconAddStatus!
enum BeaconAddStatus{
case DUPLICATE_IN_AD
case ADDED_SUCCESSFULL
case ERROR_IN_ADD
}
func addNewBeacon(beacon: BeaconData) -> BeaconAddStatus{
print("ADDNewBeacon")
print("uuid: %@ \(beacon.uuid)")
let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context: NSManagedObjectContext = appDelegate.managedObjectContext
let entityDesc: NSEntityDescription = NSEntityDescription.entityForName("Beacon", inManagedObjectContext: context)!
let request: NSFetchRequest = NSFetchRequest()
let predSearch: NSPredicate = NSPredicate(format: "(uuid = %@) AND (major = %@) AND (minor = %@) \(beacon.uuid), \(beacon.major), \(beacon.minor)")
request.entity = entityDesc
request.predicate = predSearch
do {
let existingBeacon: Beacons = try context.executeFetchRequest(request)
// success ...
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
}
}
}
了Mv信號燈類是NSManagedObject
import UIKit
import CoreData
class Beacons: NSManagedObject {
dynamic var major : NSNumber = 0.0
dynamic var minor : NSNumber = 0.0
dynamic var name : NSString = ""
dynamic var uuid : NSString = ""
}
但它從該行
的錯誤let existingBeacon: Beacons = try context.executeFetchRequest(request)
無法將類型[ '任何對象']的值爲指定類型的 '燈塔'
幫我請 謝謝:))
它的工作。非常感謝你 –