【问题标题】:How to convert multiple-character numeric format into a readable string in Swift?如何在 Swift 中将多字符数字格式转换为可读的字符串?
【发布时间】:2015-08-27 22:47:08
【问题描述】:

我正在尝试将使用 AudioFileGetGlobalInfo 获得的 AudioStreamBasicDescription 的 mFormatID 属性转换为可读字符串。 在 Objective-C 中它看起来像这样:

for (int i = 0; i < asbdCount; i++) {
  UInt32 format4cc = CFSwapInt32HostToBig(asbds[i].mFormatID);
  NSLog(@"mFormatID: %4.4s", (char*)&format4cc);
}

此代码是 Learning Core Audio 书中的一段 CAStreamFormatTester。 asbds 是指向 AudioStreamBasicDescriptions 的指针。如何将其转换为 Swift?

【问题讨论】:

    标签: swift core-audio


    【解决方案1】:

    如果asbdsUnsafePointer&lt;AudioStreamBasicDescription&gt; 类型或[AudioStreamBasicDescription] 类型,那么我相信这应该可行:

    for i in 0 ..< asbdCount {
        var format4cc = CFSwapInt32HostToBig(asbds[i].mFormatID)
        withUnsafePointer(&format4cc) { cptr in
            println(String(format: "mFormatID: %4.4s", cptr))
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 2019-02-17
      • 2014-09-23
      • 2017-06-30
      • 1970-01-01
      相关资源
      最近更新 更多