I am using xcode 6 beta 6 and I get this weird error for a function that has no params.
Here is the function
func allStudents ()-> [String]{
var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var context:NSManagedObjectContext = appDel.managedObjectContext!
var request = NSFetchRequest(entityName: "Student")
request.returnsObjectsAsFaults = false
//Set error to nil for now
//TODO: Give an actual error.
var result:NSArray = context.executeFetchRequest(request, error: nil)
var students:[String]!
for child in result{
var fullname:String = child.valueForKey("firstName") as String + " "
fullname += child.valueForKey("middleName") as String + " "
fullname += child.valueForKey("lastName") as String
students.append(fullname)
}
return students
}
and here is the call
var all = StudentList.allStudents()
Is this a bug or am I doing something wrong here?
StudentList
? Is it your class or is it a variable (in which case it should have a lower case s -studentList
) – Graciavar students:[String]!
never gets a value, it's initialized tonil
. You probably wantvar students:[String] = []
. – Procathedral