0
술어를 구현 한 후 CoreData에서 결과를 얻는데 어려움이 있습니다. 구현은 1 fetchedObject 결과 만 및 이유를 모르겠습니다.술어를 구현 하나 결과가 1 인 fetchedObject
class PhotoAlbumViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, MKMapViewDelegate {
var pin: Pin!
lazy var context: NSManagedObjectContext = {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
return appDelegate.stack!.context
}()
lazy var fetchedResultsController: NSFetchedResultsController<NSFetchRequestResult> = {
let fetchedRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Photo")
fetchedRequest.sortDescriptors = []
fetchedRequest.predicate = NSPredicate(format: "pins == %@", argumentArray: [self.pin])
return NSFetchedResultsController(fetchRequest: fetchedRequest, managedObjectContext: self.context, sectionNameKeyPath: nil, cacheName: nil)
}()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
do {
try fetchedResultsController.performFetch()
} catch let error as NSError {
print("Unable to perform fetch: \(error.localizedDescription)")
}
let fetchedObjects = fetchedResultsController.fetchedObjects
print(fetchedObjects.count) //returns 1 only
}
포토 엔티티와 핀은 둘 다 서로 관계가 있습니다.
여기에 대한 조언은 감사합니다.
Apple에서 권장하는대로 sortDescriptors가 필요합니다. – Mannopson
하나의 객체 만이 술어와 일치하는 것으로 의심됩니다. – shallowThought
왜 술어가 필요합니까? – Mannopson