ios - 无法在共享扩展中调用 CoreData 实体
问题描述
我有一个名为Item
.
import Foundation
import CoreData
@objc(Item)
public class Item: NSManagedObject, Identifiable {
...
}
我想调用Item
共享扩展,例如:
import UIKit
import Social
import CoreServices
import CoreData
class ShareViewController: SLComposeServiceViewController {
var item: Item? // <-- Use of undeclared type 'Item'
}
我已将主应用程序和共享扩展设置为相同的应用程序组和相同的容器。为什么代码可以调用Entity?
但我的说Use of undeclared type 'Item'
。如何在共享扩展中调用 CoreData?
更新
我关注@vadian 的评论,并且Item
可以在共享扩展中使用。感谢@vadian 提醒我!
修改目标成员身份后,当我运行共享扩展时,如下所示:
override func didSelectPost() {
print(Item.some method~)
}
错误说ShareExtension*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: <null> is not a valid NSFetchRequest.'
但是该方法print(Item.some method~)
可以在主应用程序中正确使用。
发生错误的原因是什么?谢谢你的帮助。
解决方案
推荐阅读
- javascript - 遍历具有包含多个对象的单个索引的数组
- python - 为什么 heroku 给我 EACCES 34.200.126.31:443 错误?
- regex - 过滤kafka消息的最佳方法应该是什么
- python - Pandas - 基于列的交集合并两个数据框
- google-cloud-platform - 用于更新 BigQuery 的 PubSub + DataFlow 或 PubSub + Function 触发器
- oracle - 在 oracle 中更改默认数据库
- java - 如何使用 do-while 循环提示并读取用户的字符串?数组列表
- python - 使用python从数据库中获取数据
- regex - 在 Fedora 中用特殊字符重命名多个文件
- r - 如何从R中的字符中删除反斜杠?