【问题标题】:'init()' is deprecated: init() will be removed in Swift 3. Use `nil`'init()' 已弃用:init() 将在 Swift 3 中删除。使用 `nil`
【发布时间】:2016-05-05 19:12:38
【问题描述】:

我正在使用此代码。

var audioUnit:AudioUnit = AudioUnit()

但在 Xcode 7.3 (Swift 2.2) 中,我收到了这个警告。知道为什么吗?我怎样才能摆脱它?

注意我是否使用nil 然后我的程序崩溃了。

【问题讨论】:

    标签: ios swift swift2 audiounit opaque-pointers


    【解决方案1】:

    AudioUnit 是 AudioComponentInstance 的类型别名,它本身就是 COpaquePointer 的类型别名。 Initializing pointers will be removed with Swift 3.0,只需将变量设置为nil。

    nil 和 AudioUnit() 应该做同样的事情。如果您的程序因nil 而崩溃,那么您可能在其他地方有错误。

    【讨论】:

    • @JarrodSmith 请确保在编辑其他人的答案时使用有效链接。我进行了修改,更正了您的无效超链接。
    猜你喜欢
    • 2016-07-09
    • 2020-04-03
    • 2018-01-03
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2016-07-10
    • 2023-03-25
    相关资源
    最近更新 更多