엔티티에 올바른 유형은 무엇입니까?Xcode 8 (신속한 3) 엔티티의 유형은 무엇입니까?
예를 들어 값을 엔티티의 속성에 저장하는 경우 아래의 세 가지 물음표를 어떤 유형 선언으로 대체해야합니까?
func setSample() {
let saveSample: <type???> = SampleEntity(context: context)
saveSample.sampleAttribute = "Save a new string."
do {
try context.save()
} catch {
print("Error with save: \(error)")
}
}
FWIW : 내가 원하는
Cannot convert value of type 'SampleEntity' to specified type 'NSEntityDescription'
Value of type 'NSEntityDescription' has no member 'sampleAttribute'
상황에 이런 식으로 뭔가 할 수있는 변수로 개체를 만들 :
func setSample() {
var saveSample: ???
if (criteria) { saveSample = Entity1(context: context) }
if (criteria) { saveSample = Entity2(context: context) }
if (criteria) { saveSample = Entity3(context: context) }
saveSample.sampleAttribute1 = "Foo"
saveSample.sampleAttribute2 = "Bar"
saveSample.sampleAttributeNth = "Etc"
do {
try context.save()
} catch {
print("Error with save: \(error)")
}
}
우리는 당신이 성취하고자하는 것에 대해 더 많은 맥락과 'Entity1'과'Entity2'의 선언이 무엇인지를 필요로합니다. – Alexander
@ Alexander Momchliov, 'Entity1','Entity2', 'Entity3'은 CoreData.xcdatamodeld에 나열된 엔티티 이름입니다. –