.propertiestofetch在Swift中获取CoreData实体中的属性数组

时间:2015-06-09 20:39:36

标签: swift core-data

我正在尝试获取实体中的属性。属性为Double_t类型。我的目标是生成Array of [Double_t]字段的所有成员" readingNumber",并将其传递给prepareForSegue以在不同的视图中制作图表。运行以下代码后,我能够打印var DistinctResults,例如:({readingNumber = 222;},{readingNumber = 114;},{readingNumber = 588;})等。现在我面临生成Array of [222, 114, 588]的困难。有人能给我一个暗示吗?非常感谢您的帮助! 最好的祝福。

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        let managedContext = appDelegate.managedObjectContext!

        let FetchRequest = NSFetchRequest(entityName: "UserReading")
        FetchRequest.propertiesToFetch = ["readingNumber"]
        FetchRequest.resultType = NSFetchRequestResultType.DictionaryResultType
        FetchRequest.returnsDistinctResults = true

            var DistinctResults: NSArray = managedContext.executeFetchRequest(FetchRequest, error: nil)!

            println(DistinctResults)

1 个答案:

答案 0 :(得分:0)

试试这个:

var clean: [String] = [""]

clean = [DistinctResults!.valueForKey("readingNumber")][0] as! [String]

...

return clean