相关疑难解决方法(0)

是否可以在Swift中使用键值观察(KVO)?

如果是这样,在Objective-C中使用键值观察时是否存在其他不存在的关键差异?

key-value-observing swift

163
推荐指数
7
解决办法
10万
查看次数

同时访问0x1c0a7f0f8,但修改需要Xcode 9 beta 4上的独占访问错误

我的项目使用Objective-C和Swift代码.当用户登录时,它会为用户首选项调用一组apis,我有一个DataCoordinator.swift类来调度API操作,我从UserDetailViewController.m类调用此类来加载用户首选项.在使用Xcode 9 beta 4将我的代码迁移到Swift 4之前,这种用法正常工作.现在当我登录时,我在DataCoordinator类中给出了这个错误.下面是我的DataCoordinator和Viewcontroller类的示例.

DataCoordinator.swift

import UIKit

@objcMembers

class DataCoordinator: NSObject {

    //MARK:- Private
    fileprivate var user = myDataStore.sharedInstance().user
    fileprivate var preferenceFetchOperations = [FetchOperation]()

    fileprivate func scheduleFetchOperation(_ operation:FetchOperation, inFetchOperations operations:inout [FetchOperation]) {
        guard  operations.index(of: operation) == nil else { return }
        operations.append(operation)
    }

    fileprivate func completeFetchOperation(_ fetchOperation:FetchOperation, withError error:Error?, andCompletionHandler handler:@escaping FetchCompletionHandler) {

        func removeOperation(_ operation:FetchOperation, fromOperations operations:inout [FetchOperation]) {
            if operations.count > 0 {
                operations.remove(at: operations.index(of: fetchOperation)!)                 
              handler(error)
            }
        }

        if preferenceFetchOperations.contains(fetchOperation) {
            removeOperation(fetchOperation, fromOperations: &preferenceFetchOperations)
        }

    } …
Run Code Online (Sandbox Code Playgroud)

crash swift swift4 ios11 xcode9-beta

25
推荐指数
6
解决办法
2万
查看次数

标签 统计

swift ×2

crash ×1

ios11 ×1

key-value-observing ×1

swift4 ×1

xcode9-beta ×1