小编Mik*_*ike的帖子

AVAudioEngine.start()崩溃,即使它包含在do/catch中

我有以下代码(重新)开始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.

ios avaudiosession swift avaudioengine

12
推荐指数
2
解决办法
1939
查看次数

如何在Swift中的[String:Class <Protocol>]类型的Dictionary中存储Class <ClassImplementingProtocol>类型的值?

我想在类型为[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没有类型参数的基类的解决方案不起作用.

generics swift

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

标签 统计

swift ×2

avaudioengine ×1

avaudiosession ×1

generics ×1

ios ×1