在新的iOS11中,我得到了一些奇怪的例外.我不明白为什么会这样.在之前的iOS中,没有这样的例外.附加日志:
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x180a5e7e8 object_isClass + 16
1 Foundation 0x181f013e8 KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 68
2 Foundation 0x181eff8ec NSKeyValueWillChangeWithPerThreadPendingNotifications + 300
3 QuartzCore 0x18555a6dc CAAnimation_setter(CAAnimation*, unsigned int, _CAValueType, void const*) + 156
4 QuartzCore 0x18555d388 -[CAPropertyAnimation setKeyPath:] + 32
5 UIKit 0x18a9b1a08 -[UIImageView startAnimating] + 876
6 UIKit 0x18a9b0e78 -[UIActivityIndicatorView startAnimating] + 48
7 UIKit 0x18a9b0174 -[UIActivityIndicatorView _didMoveFromWindow:toWindow:] + 212
8 UIKit 0x18a95845c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 712
9 UIKit 0x18a95845c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 712
10 UIKit 0x18a95845c -[UIView(Internal) _didMoveFromWindow:toWindow:] + …Run Code Online (Sandbox Code Playgroud)我正在重写应用程序的一部分,并找到了这段代码:
fileprivate let defaults = UserDefaults.standard
func storeValue(_ value: AnyObject, forKey key:String) {
defaults.set(value, forKey: key)
defaults.synchronize()
NotificationCenter.default.post(name: Notification.Name(rawValue: "persistanceServiceValueChangedNotification"), object: key)
}
func getValueForKey(_ key:String, defaultValue:AnyObject? = nil) -> AnyObject? {
return defaults.object(forKey: key) as AnyObject? ?? defaultValue
}
Run Code Online (Sandbox Code Playgroud)
当CMD点击该行时,defaults.synchronize()我看到synchronize计划已弃用.这是在代码中写的:
/*!
-synchronize is deprecated and will be marked with the NS_DEPRECATED macro in a future release.
-synchronize blocks the calling thread until all in-progress set operations have completed. This is no longer necessary. Replacements for …Run Code Online (Sandbox Code Playgroud) 我NSKeyValueObservation用来观察子类中的属性WKWebView.
它在iOS 11上运行良好,但deinit在iOS 10上崩溃.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x15209e600 of class Rakuemon.WebView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x170232da0> (
<NSKeyValueObservance 0x170259bf0: Observer: 0x17027d500, Key path: loading, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x170643ba0>
<NSKeyValueObservance 0x170643480: Observer: 0x170c72f80, Key path: estimatedProgress, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x170643330>
<NSKeyValueObservance …Run Code Online (Sandbox Code Playgroud) 我observe在使用Swift 4中的新API 时遇到了问题.
player = AVPlayer()
player?.observe(\.currentItem.status, options: [.new], changeHandler: { [weak self] (player, newValue) in
if let status = AVPlayer.Status(rawValue: (newValue as! NSNumber).intValue) {
}
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个错误
如果没有更多的上下文,表达的类型是不明确的.
我如何解决它?不确定keyPath语法.
在上面的闭包中提取AVPlayerStatus时也有一个警告
从'NSKeyValueObservedChange'转换为不相关的类型'NSNumber'总是失败"
swift ×4
ios ×3
swift4 ×2
avfoundation ×1
avplayer ×1
crash ×1
foundation ×1
ios10 ×1
ios11 ×1
ios8 ×1