也许你可以帮我在这里...... 我正在根据我的核心数据实体“植物”创建一个电子邮件正文
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let contxt: NSManagedObjectContext = appDel.managedObjectContext!
let todos = NSFetchRequest(entityName: "Plants")
var row = ""
var circle = 0 as Int
var fetchresults:Array<AnyObject> = []
fetchresults = contxt.executeFetchRequest(todos, error: nil)!
var endcircle = fetchresults.count as Int
for index in 0...endcircle {
let object = fetchresults[index] as! NSManagedObject
var name = object.valueForKey("name") as! String
var newlineimg = "nil"
var newlineplant = (name) + "<br>"
row = (row + newlineimg + newlineplant) as String
}
var mail = row
应用程序崩溃没有错误......我似乎无法在代码中找到错误...
答案 0 :(得分:2)
你枚举一个循环,它应该是:
for index in 0...(endcircle - 1)
或
for index in 0..<endcircle
当你的fetchresults.count
是例如5并且你从0到5枚举它实际上是6个循环,这就是它失败的原因。