从代码中的实体获取值列表
我有一个名为 clients 的 entity
和一个名为 clientsController 的 NSArrayController
。在我的 clients 实体中,我有一个名为 clientCompany 的属性。
在运行循环时以编程方式获取每个 clientCompany 的列表(以便代码可以从每个发现的 clientCompany 继续执行)的最直接方法是什么?我不确定在这种情况下我是否应该访问数组控制器或托管对象。
我试过了:
for (NSDictionary *key in clientsController) {
NSLog(@"%@", [key objectForKey:@"clientCompany"]);
}
没有运气,但我想我还差得很远。出于好奇,我还尝试打印数组的排列对象,但它打印为空:
NSLog(@"%@", [clientsController arrangedObjects]);
clientsController 已在程序中的其他位置初始化并访问,所以我认为这很简单,但我非常这一切都是新的。谢谢。
Update
I've had a small bit of success going the
NSManagedObjectContext
route and trying NSFetchRequest
. Requesting ObjectAtIndex:0
I can now print the first clientCompany string to the console. I just need to be able to pull all them out in a loop but the hard part is done (I hope).I've got an entity
called clients and an NSArrayController
called clientsController. In my clients entity I have an attribute called clientCompany.
What is the most straightforward way of programmatically getting a list of each clientCompany while running a loop (so that code can follow on from each discovered clientCompany)? I'm not sure whether I should be accessing the array controller or the managed object in this case.
I've tried:
for (NSDictionary *key in clientsController) {
NSLog(@"%@", [key objectForKey:@"clientCompany"]);
}
with no luck, but I think I'm way off on that. I've also tried printing the arrangedobjects of the array, out of curiosity, but it prints empty:
NSLog(@"%@", [clientsController arrangedObjects]);
clientsController has been initialised and accessed elsewhere in the program so I thought it would be straightforward but I'm very new to all this. Thanks.
Update
I've had a small bit of success going the
NSManagedObjectContext
route and trying NSFetchRequest
. Requesting ObjectAtIndex:0
I can now print the first clientCompany string to the console. I just need to be able to pull all them out in a loop but the hard part is done (I hope).如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用:
This worked for me: