相关疑难解决方法(0)

UIView, CMDeviceMotionHandler : unowned may only be applied to class and class-bound protocol types

I'm creating a UIView that listens to CMDeviceMotion Events:

class MyView: UIView{


    private var motionManager = CMMotionManager()
    let motionQueue = NSOperationQueue()


    override func awakeFromNib() {
        self.setupView()
    }

    func setupView(){
        self.motionManager.deviceMotionUpdateInterval = 0.5
        self.motionManager.startDeviceMotionUpdatesUsingReferenceFrame(.XArbitraryZVertical, toQueue: self.motionQueue, withHandler: self.motionHandler)
    }

    // MARK: - CMDeviceMotionHandler

    let motionHandler : CMDeviceMotionHandler = {
        [unowned self] (motion,error) in
    }
}
Run Code Online (Sandbox Code Playgroud)

I'd like to declare my CMDeviceMotionHandler closure as a member variable however I get the error:

'unowned' may only be applied to class and class-bound protocol …

closures swift

0
推荐指数
1
解决办法
1182
查看次数

标签 统计

closures ×1

swift ×1