填充核心数据的属性数组 [英] Filling an array with core data attributes

查看:139
本文介绍了填充核心数据的属性数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图填补我的数组。

var weights = [] 

与来自NSManaged对象的属性。我的核心数据的关系就像如下客户< - >>评估。我有考核中的权重的属性,我想,以填补我的阵列,这些值这是字符串。我的变量:

with attributes from an NSManaged object. My core data relationship is like follows Client<-->>Assessment. I have a 'weight' attribute within assessment and I would like to fill my array with these values which are strings. My variable:

var client: Client! = nil 

获取成功,我已经选择了特定的客户端,但我不知道怎么填我的数组与特定的客户称为权重评估属性的值。我只就变得如...

successfully retrieves the specific client that I have selected, but I do not know how to fill my array with the values of that particular client's assessment attribute called 'weight'. I've only gotten as far as...

client.assessment.count

它成功地显示我的评估数的客户端,但如何我每次访问这些评估的重量属性,我的阵列?

which successfully shows me the number of assessments the client has, but how to I access the weight attribute of each of those assessments for my array?

我的管理客户端与评估对象类如下:

My managed object classes for Client and Assessment are as follows:

Client.swift

Client.swift

import Foundation
import CoreData

@objc(Client)
class Client: NSManagedObject {
    @NSManaged var assessment: NSSet
}

Assessment.swift

Assessment.swift

import Foundation
import CoreData

@objc(Assessment)
class Assessment: NSManagedObject {
    @NSManaged var weight: String
    @NSManaged var client: Client
}

谁能帮我知道如何做到这一点?

Can anyone help me know how to do this?

更新:
错误我@Wain的回答得到的屏幕截图。

UPDATE: Screenshot of the error I get with @Wain 's answer.

推荐答案

您可以使用KVC来获得一组权重:

You can use KVC to get the weights in a set:

var weights: NSSet! = client.assessment.valueForKey("weight")

然后你就可以通过排序或只是要求所有对象提取一个数组。

And then you can extract an array from that by sorting or just requesting all objects.

这篇关于填充核心数据的属性数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆