如何将 UnsafeMutablePointer<UnsafeMutablePointer<Int8>?> 转换为 UnsafeMutablePointer<Unsafe

Posted

技术标签:

【中文标题】如何将 UnsafeMutablePointer<UnsafeMutablePointer<Int8>?> 转换为 UnsafeMutablePointer<UnsafeMutablePointer<Int8>>!【英文标题】:how to convert UnsafeMutablePointer<UnsafeMutablePointer<Int8>?> to UnsafeMutablePointer<UnsafeMutablePointer<Int8>>! 【发布时间】:2017-09-30 06:14:02 【问题描述】:

我正在使用 swift 4.0 重写我的 ios 应用程序的 main.swift。 这是我的 main.swift:

UIApplicationMain(CommandLine.argc,
              CommandLine.unsafeArgv
              NSStringFromClass(MyAPP.self),
              NSStringFromClass(AppDelegate.self))

这里有一个编译错误:

Cannot convert value of type 'UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>' to expected argument type 'UnsafeMutablePointer<UnsafeMutablePointer<Int8>>!'

有人知道如何在这里将UnsafeMutablePointer&lt;UnsafeMutablePointer&lt;Int8&gt;?&gt; 转换为UnsafeMutablePointer&lt;UnsafeMutablePointer&lt;Int8&gt;&gt;! 吗?

【问题讨论】:

Xcode 8 beta 6: main.swift won't compile的可能重复 【参考方案1】:
UIApplicationMain(
    CommandLine.argc,
    UnsafeMutablePointer(CommandLine.unsafeArgv),
    NSStringFromClass(MyAPP.self),
    NSStringFromClass(AppDelegate.self)
)

【讨论】:

考虑添加一些说明您的代码解决问题的原因。 UnsafeMutableRawPointer(CommandLine.unsafeArgv) 已弃用。【参考方案2】:

请检查:

UIApplicationMain(  
    CommandLine.argc,  
    UnsafeMutableRawPointer(CommandLine.unsafeArgv)  
        .bindMemory(  
            to: UnsafeMutablePointer<Int8>.self,  
            capacity: Int(CommandLine.argc)
        ),  
    NSStringFromClass(MyAPP.self),  
    NSStringFromClass(AppDelegate.self)  
)  

【讨论】:

这是一个弃用的答案

以上是关于如何将 UnsafeMutablePointer<UnsafeMutablePointer<Int8>?> 转换为 UnsafeMutablePointer<Unsafe的主要内容,如果未能解决你的问题,请参考以下文章

如何将 UnsafeMutablePointer<Void> 转换为 UInt8?

如何快速将自己转换为 UnsafeMutablePointer<Void> 类型

如何快速将自己转换为 UnsafeMutablePointer<Void> 类型

Swift:无法将“UnsafeMutablePointer”类型的值转换为预期的参数类型“UnsafeMutablePointer”

如何转换 UnsafePointer<UnsafeMutablePointer<Float>>?到 UnsafeMutablePointer<UnsafeMutableP

将 UnsafeMutablePointer<Int16> 转换为 UInt8