我只是从CoreData
获取数据,并希望将其打印到tableView
所以我尝试将数据放入Mutable array
,以便我可以通过Mutable array
访问日期TableView
但是我收到了这个错误
以下是我的代码
import UIKit
import CoreData
class TableView: UIViewController, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
var desc_arr: [String] = []
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context: NSManagedObjectContext = appDel.managedObjectContext
let request = NSFetchRequest(entityName: "Expense")
request.returnsObjectsAsFaults = false
do {
let results = try context.executeFetchRequest(request)
if results.count > 0 {
for result in results as! [NSManagedObject] {
if let desc = result.valueForKey("desc") as? String {
print(desc)
for i in desc{
desc_arr.append(i)
}
}
if let amt = result.valueForKey("amt") as? String{
print(amt)
}
}
}
} catch {
print("Fetch Failed")
}
print(desc_arr)
}
}
答案 0 :(得分:0)
而不是
if let desc = result.valueForKey("desc") as? String
尝试
if let desc = result.valueForKey("desc") as? AnyObject
干杯!