问题
I'm having issues in a larger project, and boiled it down to this simple code. For demo purposes, I have created a new Swift project with the following in a Model.swift file:
import Foundation
import CoreData
class A: NSManagedObject {
@NSManaged var foo: String
}
final class B: A {
@NSManaged var bar: String
}
func testB(obj: B) -> String {
return "\(obj.foo) \(obj.bar)"
}
This compiles, but the linker complains about accessing bar
:
Undefined symbols for architecture armv7:
"__TFC21TestFinalManagedClass1Bg3barSS", referenced from:
__TF21TestFinalManagedClass5testBFCS_1BSS in Model.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The combination of an @NSManaged var
in a final class
seems to be what causes the error. (The class inheritance from A
is included to demonstrate that the foo
property is accessible on an object of type B
, but not the bar
property.)
I am using Xcode Version 6.1 (6A1052d).
Is there some rule hidden in the documentation about marking an NSManagedObject
subclass as final? Or is this just a bug in the compiler/linker?
回答1:
This issue has been resolved in Xcode 6.3 beta.
来源:https://stackoverflow.com/questions/26616893/swift-linker-error-when-accessing-nsmanaged-properties-of-a-final-class