使用Swift fetch

时间:2017-06-23 14:59:34

标签: ios swift3 xcode8

我正在使用Xcode版本8.3.3和Swift 3.我的手机正在运行iOS 10.3.2。

当我使用该应用时,会出现此问题。

我的手机应用中发生间歇性错误。将数据上载到Web服务后,将调用以下代码来更新Core Data中的对象。我没有看到对象导致错误的原因:

func uploadedMarker(_ oldRouteId: Int16, stepId: Double, newRouteId: Int16) {

    do {

        let request = NSFetchRequest<NSFetchRequestResult>(entityName: "HoldMarkers")
        let routePredicate = NSPredicate(format: "routeId = %i", oldRouteId)
        let stepPredicate = NSPredicate(format: "stepId = %f", stepId)
        request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [routePredicate, stepPredicate])
        request.returnsObjectsAsFaults = false
        let markers = try self.context.fetch(request) as! [HoldMarkers]

        if markers.count > 0 {

            let marker = markers.first!
            marker.uploaded = true
            marker.routeId = newRouteId

            do {

                try marker.validateForUpdate()
                self.appDelegate.saveContext()
            }
            catch {

                let nserror = error as NSError
                NSLog("uploadedMarker - Core Data Error - Updating HoldMarkers :\(nserror), \(nserror.userInfo)")
            }
        }
    }
    catch {

        let nserror = error as NSError
        NSLog("uploadedMarker - Core Data Error - Fetching HoldMarkers :\(nserror), \(nserror.userInfo)")
    }
}

上下文定义为:

let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext

就像我说的,这是一个间歇性的错误:

-[MKPolyline _genericValueForKey:withIndex:flags:]: unrecognized selector sent to instance 0x17049a860
1   CoreFoundation  __exceptionPreprocess + 124
2   libobjc.A.dylib objc_exception_throw + 52
3   CoreFoundation  -[NSObject(NSObject) doesNotRecognizeSelector:] + 136
4   CoreFoundation  ___forwarding___ + 912
5   CoreFoundation  __forwarding_prep_0___ + 88
6   CoreData    _PF_Handler_Public_GetProperty + 244
7   Foundation  -[NSFunctionExpression expressionValueWithObject:context:] + 736
8   Foundation  -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 224
9   Foundation  -[NSCompoundPredicateOperator evaluatePredicates:withObject:substitutionVariables:] + 440
10  Foundation  -[NSCompoundPredicate evaluateWithObject:substitutionVariables:] + 272
11  CoreData    -[NSManagedObjectContext executeFetchRequest:error:] + 2796
12  Parks-Tracker   RouteViewController.uploadedMarker(Int16, stepId : Double, newRouteId : Int16) -> () (RouteViewController.swift:1371)
13  Parks-Tracker   @objc RouteViewController.uploadedMarker(Int16, stepId : Double, newRouteId : Int16) -> () (RouteViewController.swift:0)
14  Parks-Tracker   RouteViewController.(updateRoute(Double, longitude : Double, timestamp : Date, routeId : Int16, stepId : Double, segment : Int16, complete : Bool) -> ()).(closure #2) (RouteViewController.swift:1114)
15  Parks-Tracker   thunk for @callee_owned (@owned NSDictionary, @owned NSError?, @unowned Int16, @unowned Double) -> () (RouteViewController.swift:0)
16  Parks-Tracker   thunk for @callee_unowned @convention(block) (@unowned NSDictionary, @unowned NSError?, @unowned Int16, @unowned Double) -> () (RouteViewController.swift:0)
17  Parks-Tracker   RouteViewController.(callRouteUpdate(Double, longitude : Double, complete : Bool, routeId : Int16, stepId : Double, segment : Int16, conditionDescription : String, markerImage : NSData?, routeName : String, destinationId : Int16, completion : (NSDictionary, NSError?, Int16, Double) -> ()) -> ()).(closure #1) (RouteViewController.swift:1262)
18  Parks-Tracker   thunk for @callee_owned (@owned Data?, @owned URLResponse?, @owned Error?) -> () (LoginViewController.swift:0)

0 个答案:

没有答案