我有以下代码(重新)开始AVAudioEngine
连接到AVAudioEngineConfigurationChangeNotification
:
do {
try self.engine.start()
} catch {
DDLogError("could not start sound engine")
self.soundEnabled = false
return
}
Run Code Online (Sandbox Code Playgroud)
self.engine定义为
private let engine = AVAudioEngine()
Run Code Online (Sandbox Code Playgroud)
但是,我经常通过Crashlytics收到崩溃报告
致命异常:com.apple.coreaudio.avfaudio错误561015905
在包含的线上try self.engine.start()
.
561015905是AVAudioSessionErrorCodeCannotStartPlaying
从我的理解,这应该是一个NSError
错误代码,而不是一个例外,应该由我catch
在上面的代码中的空白捕获.不过,该应用程序似乎只是崩溃了.我错过了什么?
我知道有些情况下应用程序会在可能发生此错误的后台唤醒,我会很好,只要我能够以某种方式发现它,就像我想的那样do/catch
.
我想在类型为[String:SomeClass]的Dictionary中存储一个更专业的类型.下面是一些说明我的问题的示例代码(也可以在https://swiftlang.ng.bluemix.net/#/repl/579756cf9966ba6275fc794a上进行):
class Thing<T> {}
protocol Flavor {}
class Vanilla: Flavor {}
var dict = [String:Thing<Flavor>]()
dict["foo"] = Thing<Vanilla>()
Run Code Online (Sandbox Code Playgroud)
它会产生错误ERROR at line 9, col 28: cannot assign value of type 'Thing<Vanilla>' to type 'Thing<Any>?'
.
我已经尝试过铸造,Thing<Vanilla>() as Thing<Flavor>
但这会产生错误cannot convert value of type 'Thing<Vanilla>' to type 'Thing<Flavor>' in coercion
.
我也尝试将Dictionary定义为类型,[String:Thing<Any>]
但也不会改变任何东西.
如何在Thing
不诉诸普通的情况下创建不同s 的集合[String:AnyObject]
?
我还应该提一下,Thing
我没有定义类(实际上它是关于BoltsSwift Task
的),因此创建Thing
没有类型参数的基类的解决方案不起作用.