相关疑难解决方法(0)

iOS 11. KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED是什么意思?

在新的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)

crash ios ios11

19
推荐指数
1
解决办法
6730
查看次数

如何在Swift中使用KVO for UserDefaults?

我正在重写应用程序的一部分,并找到了这段代码:

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)

key-value-observing foundation ios swift

16
推荐指数
3
解决办法
6718
查看次数

为什么你要删除ios8中的观察者?

在阅读iOS 9的这篇文章后,我知道您不再需要删除Observer.

但是对于iOS 8,您需要viewControllerdeinit方法中删除Observer.但我无法理解它.如果一个viewController被释放,那么它的DEAD不是吗?为什么我们需要做一个removeObserver.它是一个观察者就像打电话给一个永远不会拿起电话的死人

我不明白的是什么?

nsnotificationcenter ios swift ios8

5
推荐指数
1
解决办法
1103
查看次数

iOS 10 - 在deinit上发生NSKeyValueObservation崩溃

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)

key-value-observing swift ios10 swift4

5
推荐指数
2
解决办法
2697
查看次数

Swift 4切换到新的观察API

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'总是失败"

key-value-observing avfoundation avplayer swift swift4

3
推荐指数
1
解决办法
964
查看次数