내가 이 프로토콜:
protocol ManagedObjectProtocol {
associatedtype Entity
static var identifierKey: String { get }
static func fetchRequest() -> NSFetchRequest<NSFetchRequestResult>
func toEntity() -> Entity?
}
나는지 확인하는 일부의 내 NSManagedObject 클래스를 확장자를 가진 다음과 같다:
extension AppEntity: ManagedObjectProtocol {
typealias Entity = App
static var identifierKey: String {
return "articleId"
}
func toEntity() -> Entity? {
return nil
}
}
하려고 할 때 아카이브와 새로운 Xcode13 내가 이 오류가 발생할 수 있습니다.
형'AppEntity'준수하지 않 프로토콜'ManagedObjectProtocol'
하지만 난 그냥을 실행하려고 이 코드는 장치에 구축 괜찮습니다.
그것은 건축/보관과 잘 Xcode12 이전 버전만으로 새로운 Xcode13 일(및 Xcode13.1)내가 문제입니다. 가 될 수 있는 문제입니까? 어떻게 그것을 해결할 수 있습니까?
하나 더 많은 것을 얻을 때 오류를 보관하지 않을 때는 디버그 빌드. 이 코드는 앞을 얻을 entity:
func get<Entity: NSManagedObject>
(with predicate: NSPredicate? = nil,
sortDescriptors: [NSSortDescriptor]? = nil,
fetchLimit: Int? = nil,
inContext context: NSManagedObjectContext? = nil,
completion: @escaping (Result<[Entity], Error>) -> Void) {
if let ctx = context {
coreData.performTask({ (context) in
do {
let fetchRequest = Entity.fetchRequest()
fetchRequest.predicate = predicate
fetchRequest.sortDescriptors = sortDescriptors
if let fetchLimit = fetchLimit {
fetchRequest.fetchLimit = fetchLimit
}
let results = try context.fetch(fetchRequest) as? [Entity]
completion(.success(results ?? []))
} catch {
completion(.failure(error))
}
}, inContext: ctx)
} else {
coreData.performForegroundTask { context in
do {
let fetchRequest = Entity.fetchRequest()
fetchRequest.predicate = predicate
fetchRequest.sortDescriptors = sortDescriptors
if let fetchLimit = fetchLimit {
fetchRequest.fetchLimit = fetchLimit
}
let results = try context.fetch(fetchRequest) as? [Entity]
completion(.success(results ?? []))
} catch {
completion(.failure(error))
}
}
}
}
제가 이 오류 메시지:
형'Entity'멤버가 없'fetchRequest'
무엇이 잘못입니까? 어떻게 해결할 수 있는 이러한 핵심 데이터 오류를 보관할 때?
감사에 대한 도움
편집:
예를 하나 더 들에 대한 도우미는 방법에는 나는 오류가와 no member fetchRequest
:
func count(entity: NSManagedObject.Type,
with predicate: NSPredicate? = nil,
fetchLimit: Int? = nil,
completion: @escaping (Result<Int, Error>) -> Void) {
coreData.performForegroundTask { context in
do {
let fetchRequest = entity.fetchRequest()
fetchRequest.predicate = predicate
if let fetchLimit = fetchLimit {
fetchRequest.fetchLimit = fetchLimit
}
let count = try context.count(for: fetchRequest)
completion(.success(count))
} catch {
completion(.failure(error))
}
}
}