Swift - 关闭中inout list参数的EXC_BAD_ACCESS

时间:2018-02-09 06:40:26

标签: ios swift

当我运行以下函数$('.c_delivery_types').append('<option selected></option>').select2({ placeholder: "Select delivery types", allowClear: true }); 时,使用以下主过程,所需的效果是通过引用传入列表,并允许同步(或异步)过程将元素追加到后面。列表,充当数据馈送:

subscribe

下面是一个稍微抽象的版本(因为它使用了需要用户名和密码进行复制的特定API),这些代码目前正在造成问题:

// Main procedure
override func viewDidLoad() {
    super.viewDidLoad()
    var queue : [String] = []
    subscribe(prefix: "weight", dataFeed: &queue) // calling procedure here  
}

// Function where the error is occuring
func subscribe(prefix : String, dataFeed : inout [String]){
    ParticleCloud.sharedInstance().subscribeToAllEvents(withPrefix: prefix, handler: { (eventOpt :ParticleEvent?, error : Error?) in
        if let _ = error {
            eprint (message: "could not subscribe to events")
        } else {
            DispatchQueue.main.sync(execute: {
                if let event = eventOpt{
                    if let eventData = event.data {
                        eprint(message: "got event with data \(eventData)")
                        dataFeed.append(eventData) // EXC_BAD_ACCESS (code=1, ...)
                    }
                }
            })
        }
    })
}

有谁知道为什么我在这里收到// Function where the error is occuring func foo(prefix : String, dataFeed : inout [String]){ API.call(withPrefix: prefix, handler: { (eventOpt :Event?, error : Error?) in if let _ = error { print("error!") } else { DispatchQueue.main.sync(execute: { if let event = eventOpt{ if let eventData = event.data { dataFeed.append(eventData) // EXC_BAD_ACCESS (code=1, ...) } } }) } }) } 错误?

0 个答案:

没有答案