小编Ben*_*Ben的帖子

NSManageObjectContext - 类不是键@count的键值编码兼容

我有一个带有RestKit库和CoreData的iOS应用程序.从Xcode8开始,我可以看到比以前更多的日志,其中一个对我没有任何意义.

error: An observer of NSManagedObjectContextDidSaveNotification illegally threw an exception.  Objects saved = {
inserted = "{(\n)}";
managedObjectContext = "<_PFWeakReference: 0x600000621560>";
updated = "{(\n ... )}";
} 
and exception = [<_PFWeakReference 0x600000621560> valueForUndefinedKey:]: this class is not key value coding-compliant for the key @count. with userInfo = {
NSTargetObjectUserInfoKey = "<_PFWeakReference: 0x600000621560>";
NSUnknownUserInfoKey = "@count";
Run Code Online (Sandbox Code Playgroud)

到目前为止,我能理解的是对managedObjectContext的弱引用(错误上面的内容)使用了错误的键,但我无法弄清楚如何调试它.

与此问题相关的所有NSManagedObjects似乎都是集合.主要来自OneToMany或ManyToMany关系的NSSet.

然后我发现了这个Apple文档:

除@count外,所有集合运算符都需要集合运算符右侧的键路径.

但是,我看不到当前使用此密钥的任何谓词或CoreData请求.

我重新生成了所有的NSManagedObject模型,并仔细检查它们之间的所有反向关系,但它没有帮助我摆脱它.

这个应用程序运行正常,但我找不到任何解决方案来删除此警告.

core-data ios restkit xcode8

9
推荐指数
1
解决办法
1050
查看次数

从CBCentralManagerDelegate回调以在IOS8上检索CBPeripheral

我有一个管理BTLE通信的BluetoothManager类.我可以扫描并连接到CBPeripheral并发现服务或特征.我有来自CBCentralManagerDelegate和CBPeripheralDelegate的良好回调

当我连接到CBPeripheral时,我在CoreData中保存UUIDString以在我重新启动应用程序时检索此外围设备.

这是我重新启动应用程序时检索外围设备的Swift代码:

func retrievePeripheralsWithIdentifiers(identifiers: [AnyObject]!){
    let data = self.centralManager.retrievePeripheralsWithIdentifiers(identifiers)

    println("Data retrieved: \(data)")

    for peripheral in data as [CBPeripheral] {

        println("Peripheral : \(peripheral)")
        peripheral.delegate = self
        centralManager.connectPeripheral(peripheral, options: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

这就是我所拥有的:

Data retrieved: [<CBPeripheral: 0x1669fcd0, identifier = XXXXX, name = Peripheral1, state = disconnected>]
Peripheral : <CBPeripheral: 0x1669fcd0, identifier = XXXXX, name = Peripheral1, state = disconnected>
Run Code Online (Sandbox Code Playgroud)

我可以找到我的一个外围没有任何问题.但是当我调用"centralManager.connectPeripheral(peripheral,options:nil)"这一行时,我没有任何回复.

这些方法

func centralManager(central: CBCentralManager!, didRetrievePeripherals peripherals: [AnyObject]!)
func centralManager(central: CBCentralManager!, didConnectPeripheral peripheral: CBPeripheral!)
func centralManager(central: CBCentralManager!, didFailToConnectPeripheral peripheral: CBPeripheral!, error: NSError!) …
Run Code Online (Sandbox Code Playgroud)

objective-c ios core-bluetooth bluetooth-lowenergy swift

6
推荐指数
1
解决办法
6269
查看次数

iOS Swift Coordinator 模式和导航控制器的后退按钮

我正在使用模式MVVM+Coordinator。我的每个控制器都是由coordinators. 但是,当点击Navigation控制器的后退按钮时,停止我的协调器的正确方法是什么?

class InStoreMainCoordinator: NavigationCoordinatorType, HasDisposeBag {

    let container: Container

    enum InStoreMainChildCoordinator: String {
        case menu = "Menu"
        case locations = "Locations"
    }

    var navigationController: UINavigationController
    var childCoordinators = [String: CoordinatorType]()

    init(navigationController: UINavigationController, container: Container) {
        self.navigationController = navigationController
        self.container = container
    }

    func start() {
        let inStoreMainViewModel = InStoreMainViewModel()
        let inStoreMainController = InStoreMainController()
        inStoreMainController.viewModel = inStoreMainViewModel

        navigationController.pushViewController(inStoreMainController, animated: true)
    }
}
Run Code Online (Sandbox Code Playgroud)

mvvm ios swift rx-swift coordinator-pattern

6
推荐指数
1
解决办法
5223
查看次数