swift内存泄露,与OC的混合
1. 避免内存泄露 1)由于闭包引用了self而可能导致的内存泄露,必须如下这样写: weak var weakSelf = self; nearByVM = BMKNearByViewModel(onResult: { (address) -> () in weakSelf?.onGetAddress(address); }); 或者这样 nearByVM = BMKNearByViewModel(onResult: {[weak self] (address) -> () in self?.onGetAddress(address); });
2)使用delegate代理循环引用可能导致的内存泄露,必须如下这样写: weakvar delegate : BMKMapViewDelegate? 2. swift的枚举与oc的枚举比较 枚举值后加value 如 3.It's the same as the Objective-C API,but uses Swift's syntax. NSNotificationCenter.defaultCenter().addObserver( self,selector:"batteryLevelChanged:",name:UIDeviceBatteryLevelDidChangeNotification,object:nil) If your observer does not inherit from an Objective-C object,you must prefix your method with @objcfuncbatteryLevelChanged(notification:NSNotification){ //dostuff } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |