草庐IT

UInt8List

全部标签

string - 如何将 String 转换为 UnsafePointer<UInt8> 和长度

当我使用NSOutputStream时的write方法funcwrite(_buffer:UnsafePointer,maxLengthlength:Int)->Int我不知道如何转换String至UnsafePointer和长度我怎样才能快速做到这一点? 最佳答案 您必须先将字符串转换为UTF-8数据letstring="foobar"letdata=string.dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion:false)!然后写入输出流letoutputS

string - 如何将 String 转换为 UnsafePointer<UInt8> 和长度

当我使用NSOutputStream时的write方法funcwrite(_buffer:UnsafePointer,maxLengthlength:Int)->Int我不知道如何转换String至UnsafePointer和长度我怎样才能快速做到这一点? 最佳答案 您必须先将字符串转换为UTF-8数据letstring="foobar"letdata=string.dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion:false)!然后写入输出流letoutputS

ios - Swift 中的 Int 到 UInt(反之亦然)位转换

我正在寻找一种直接的方法来将Int的位值转换为UInt,反之亦然。例如(为简单起见,使用8位整数)我想实现以下目标:letunsigned:UInt8=toUInt8(-1)//unsignedis255or0xffletsigned:Int8=toInt8(0xff)//signedis-1起初我想出了以下解决方案:letunsigned=unsafeBitCast(Int8(-1),UInt8.self)letsigned=unsafeBitCast(UInt8(0xff),Int8.self)但Apple在“unsafeBitCast()”文档中声明如下:..Caution::B

ios - Swift 中的 Int 到 UInt(反之亦然)位转换

我正在寻找一种直接的方法来将Int的位值转换为UInt,反之亦然。例如(为简单起见,使用8位整数)我想实现以下目标:letunsigned:UInt8=toUInt8(-1)//unsignedis255or0xffletsigned:Int8=toInt8(0xff)//signedis-1起初我想出了以下解决方案:letunsigned=unsafeBitCast(Int8(-1),UInt8.self)letsigned=unsafeBitCast(UInt8(0xff),Int8.self)但Apple在“unsafeBitCast()”文档中声明如下:..Caution::B

ios - Swift 编译器错误 : “Cannot invoke ' map' with an argument list of type '((_) -> _)' ”

我有一个要映射的范围,但出现错误“无法使用类型为‘((_)->_)’的参数列表调用‘map’”代码是这样的letpatterns=(0...5).map{verseNuminletverseNumberStartPattern="\"verse-num\">\(verseNum)(?:\\s?)?(.*?)\\s\(parsedVerse.chapterStart)\\s"ifverseNum==1{returnchapterStartPattern+"(.*?)如果我取出闭包中的所有内容并只返回“”,那么编译器不会报错。但是,即使我添加一行而不是返回空字符串,编译器也会报错,例如fo

ios - Swift 编译器错误 : “Cannot invoke ' map' with an argument list of type '((_) -> _)' ”

我有一个要映射的范围,但出现错误“无法使用类型为‘((_)->_)’的参数列表调用‘map’”代码是这样的letpatterns=(0...5).map{verseNuminletverseNumberStartPattern="\"verse-num\">\(verseNum)(?:\\s?)?(.*?)\\s\(parsedVerse.chapterStart)\\s"ifverseNum==1{returnchapterStartPattern+"(.*?)如果我取出闭包中的所有内容并只返回“”,那么编译器不会报错。但是,即使我添加一行而不是返回空字符串,编译器也会报错,例如fo

hutool的json工具完成list和json转换

将json和list相互转换importcn.hutool.json.JSONArray;importcn.hutool.json.JSONUtil;//List转Json,maps是List类型的参数Stringjson=JSONUtil.toJsonStr(maps);System.out.println("这是json字符串:"+json);//Json转ListJSONArrayobjects=JSONUtil.parseArray(json);Listmaps1=JSONUtil.toList(objects,Map.class);System.out.println("这是list

ios - 在 UInt 和 Int 之间快速转换

我有以下方法varphotos=[MWPhoto]=[MWPhoto]()funcnumberOfPhotosInPhotoBrowser(photoBrowser:MWPhotoBrowser!)->UInt{returnself.photos.count}funcphotoBrowser(photoBrowser:MWPhotoBrowser!,photoAtIndexindex:UInt)->MWPhotoProtocol!{returnself.photos[index]}然而,首先我得到IntisnotconversionbletoUInt(因为self.photos.cou

ios - 在 UInt 和 Int 之间快速转换

我有以下方法varphotos=[MWPhoto]=[MWPhoto]()funcnumberOfPhotosInPhotoBrowser(photoBrowser:MWPhotoBrowser!)->UInt{returnself.photos.count}funcphotoBrowser(photoBrowser:MWPhotoBrowser!,photoAtIndexindex:UInt)->MWPhotoProtocol!{returnself.photos[index]}然而,首先我得到IntisnotconversionbletoUInt(因为self.photos.cou

c# - 使用 LINQ 将 'ArrayList' 转换为 'List<string>'(或 'List<T>')

我想转换一个ArrayList到List使用LINQ。我试过ToList()但这种方法不起作用:ArrayListresultsObjects=newArrayList();Listresults=resultsObjects.ToList(); 最佳答案 您的代码实际上显示了一个List而不是单个ArrayList.如果你真的只有一个ArrayList,你可能想要:ArrayListresultObjects=...;Listresults=resultObjects.Cast().ToList();Cast需要打电话,因为Arr