Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我正在尝试在 Swift中复制一些Objective C cocoa.一切都很好,直到我遇到以下情况: // Set a new type and creator:unsigned long type = 'TEXT';unsigned long creator = 'pdos'; 如何从这样的单引号字符文字创建Int64(或正确的Swift等价物)? 类型: public typealias 我正在尝试在 Swift中复制一些Objective C cocoa.一切都很好,直到我遇到以下情况:
// Set a new type and creator:unsigned long type = 'TEXT';unsigned long creator = 'pdos';

如何从这样的单引号字符文字创建Int64(或正确的Swift等价物)?

类型:

public typealias AEKeyword = FourCharCodepublic typealias OSType = FourCharCodepublic typealias FourCharCode = UInt32
我在我的Cocoa Scripting应用程序中使用它,它认为字符> 0x80正确
func OSTypeFrom(string : String) -> UInt {  var result : UInt = 0  if let data = string.dataUsingEnCoding(NSMacOSRomanStringEnCoding) {    let bytes = UnsafePointer<UInt8>(data.bytes)    for i in 0..<data.length {      result = result << 8 + UInt(bytes[i])    }  }  return result}

编辑:

另外

func fourCharCodeFrom(string : String) -> FourCharCode{  assert(string.count == 4,"String length must be 4")  var result : FourCharCode = 0  for char in string.utf16 {    result = (result << 8) + FourCharCode(char)  }  return result}

或者仍然很快

func fourCharCode(from string : String) -> FourCharCode{  return string.utf16.reduce(0,{[+++] << 8 + FourCharCode()})}
总结

以上是内存溢出为你收集整理的Swift相当于Objective-C FourCharCode单引号文字(例如’TEXT’)全部内容,希望文章能够帮你解决Swift相当于Objective-C FourCharCode单引号文字(例如’TEXT’)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Swift相当于Objective-C FourCharCode单引号文字(例如’TEXT’)_app_内存溢出

Swift相当于Objective-C FourCharCode单引号文字(例如’TEXT’)

Swift相当于Objective-C FourCharCode单引号文字(例如’TEXT’),第1张

概述我正在尝试在 Swift中复制一些Objective C cocoa.一切都很好,直到我遇到以下情况: // Set a new type and creator:unsigned long type = 'TEXT';unsigned long creator = 'pdos'; 如何从这样的单引号字符文字创建Int64(或正确的Swift等价物)? 类型: public typealias 我正在尝试在 Swift中复制一些Objective C cocoa.一切都很好,直到我遇到以下情况:
// Set a new type and creator:unsigned long type = 'TEXT';unsigned long creator = 'pdos';

如何从这样的单引号字符文字创建Int64(或正确的Swift等价物)?

类型:

public typealias AEKeyword = FourCharCodepublic typealias OSType = FourCharCodepublic typealias FourCharCode = UInt32
我在我的Cocoa Scripting应用程序中使用它,它认为字符> 0x80正确
func OSTypeFrom(string : String) -> UInt {  var result : UInt = 0  if let data = string.dataUsingEnCoding(NSMacOSRomanStringEnCoding) {    let bytes = UnsafePointer<UInt8>(data.bytes)    for i in 0..<data.length {      result = result << 8 + UInt(bytes[i])    }  }  return result}

编辑:

另外

func fourCharCodeFrom(string : String) -> FourCharCode{  assert(string.count == 4,"String length must be 4")  var result : FourCharCode = 0  for char in string.utf16 {    result = (result << 8) + FourCharCode(char)  }  return result}

或者仍然很快

func fourCharCode(from string : String) -> FourCharCode{  return string.utf16.reduce(0,{ << 8 + FourCharCode()})}
总结

以上是内存溢出为你收集整理的Swift相当于Objective-C FourCharCode单引号文字(例如’TEXT’)全部内容,希望文章能够帮你解决Swift相当于Objective-C FourCharCode单引号文字(例如’TEXT’)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1036019.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存