jeudi 26 mars 2015

Swift throws compilation error on Fetching objects in file other than AppDelgate and accessing element in NSOrderedSet

I have a CoreDataManager.Swift where I delegated the creation of PersistentStore Coordinator, ManagedObjectContext and NSManagedObjectModel


I have the following function where Entity is a NSManagedObject and timeStamps is NSOrderedSet. In data model timeStamps is one to many relationship to another NSManagedObject TimeStamp



func fetchData(){
let fetchRequest = NSFetchRequest(entityName:"Entity")

var error: NSError?

let fetchedResults =
CoreDataManager.sharedInstance.managedObjectContext!.executeFetchRequest(fetchRequest,
error: &error) as! [NSManagedObject]?

//If error then return...

for entity in fetchedResults as! [Entity]
{
println(entity.name)
println(entity.timeStamps)
for eS in entity.timeStamps
{
println(eS.time) //OK in AppDelegate but throw compilation error in CoreDataManager.swift
// Error thrown is AnyObject does not have a member name time
//If I force to TimeStamp then the fault on timeStamps is not fired.


}
}
}


The issues is, it works fine if I have that function in AppDelegate but throws compilation errors in CoreDataManager. If I try to force it as TimeStamp then the fault on timeStamps is not fired.


Thanks for any help




Aucun commentaire:

Enregistrer un commentaire