I have a few functions that return promises. if I add any code within the then block, like a variable declaration, my then I get a compile error. I'm pretty confused as to why and any help is appreciated.

(no errors above)

(above error is)
/Users/matthewchung/Documents/Versame/ios/starling-ios/Starling/Classes/Realm/RealmManager.swift:41:29: Cannot convert return expression of type 'Promise
and here is how I am creating my promises
func createChildWordSamples(filename:String, childName:String) -> Promise<Array<String>> {
return Promise { fulfill,reject in
let startedTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC)))
dispatch_after(startedTime, dispatch_get_main_queue(), {
if let url = NSBundle.mainBundle().URLForResource(filename, withExtension: "csv") {
//reading
do {
let text = try NSString(contentsOfURL: url, encoding: NSUTF8StringEncoding)
let lines = text.componentsSeparatedByString("\n")
let realm = try! Realm()
try! realm.write({ () -> Void in
for line in lines {
let components = line.componentsSeparatedByString(",")
var date = self.formatter.dateFromString(components[0])!
date = NSDate(timeIntervalSince1970: date.timeIntervalSince1970 + self.delta!)
let info:[String:AnyObject] = ["childId":childName, "count":Int(components[1])!, "interval":Int(components[2])!, "timestamp":date]
let sample = WordSample(info: info)
realm.add(sample, update: false)
}
})
fulfill(lines)
}
catch {/* error handling here */}
}
})
}
}
Sorry for the delayed response. If you haven't already, try specifying the return type in your closures that are returning promises. This has historically satisfied the Swift compiler in circumstances like these.
got it. thanks!
Most helpful comment
Sorry for the delayed response. If you haven't already, try specifying the return type in your closures that are returning promises. This has historically satisfied the Swift compiler in circumstances like these.