草庐IT

byte-range

全部标签

Swift 数组下标扩展 "Range<T> is not convertible to Int"

我在Array上定义一个扩展来覆盖Slice的创建:structS{privatevararray:[T]=[]privatevarfirst=0privatevarlen=0init(_array:[T],_range:Range?=nil){self.array=arrayifletrange=range{self.first=range.startIndexself.len=range.endIndex}else{self.first=0self.len=array.count}}}extensionArray{subscript(subRange:Range)->S{retur

arrays - "fatal error: Array index out of range swift"

代码为:classSingleton{classvarsharedInstance:Singleton{structStatic{staticvarinstance:Singleton?=nilstaticvartoken:dispatch_once_t=0}dispatch_once(&Static.token){Static.instance=Singleton()}returnStatic.instance!}varprayerArray=Array()}和:overridefunctableView(tableView:UITableView,didSelectRowAtInd

iOS Swift 3 BLE CBCharacteristic/Size 8 Bytes (4 Words)/如何分隔单词

我想从蓝牙模块读取数据。有一个特征有4个值,存储在8个字节/4个字中。这是存储在characteristic.value中的数据:0x010x010x000x010x040x050x000x01我使用Swift3。这是代码funcperipheral(_peripheral:CBPeripheral,didUpdateValueForcharacteristic:CBCharacteristic,error:Error?){letdata=characteristic.valueletdataString=String(data:data!,encoding:String.Encodi

swift - 'Int' 不可转换为 'Range<Int>'

我最近从Xcode6.0迁移到Xcode6.1,我在一些以前编译正常的代码上遇到了编译错误。这是导致错误的行:self.possibleWidgetUnits[widgetSizes.Small.rawValue]=WidgetFormat(width:1.0,height:1.0)错误是:'Int'isnotconvertibleto'Range'这是我的变量声明:typealiasWidgetFormat=(width:Int,height:Int)varpossibleWidgetUnits:[WidgetFormat]这些行有什么问题?编辑:enumwidgetSizes:In

ios - swift - fatal error : Array index out of range

我正在尝试用每个增加0.1的数字填充一个数组,例如:[0.1,0.2,0.3...]此代码给我错误:fatalerror:数组索引超出范围。我错过了什么?我觉得我在声明错误。我会把它存成Double类型的结构。我的代码importUIKitclassPrecoDomicilioViewController:UIViewController,UIPickerViewDelegate,UIPickerViewDataSource{@IBOutletvareuros:UIPickerView!varpickerData:[Double]=[]overridefuncviewDidLoad()

ios - 核心 ML : UIImage from RGBA byte array not fully shown

结合CoreML,我尝试使用以下代码在UIImage中显示RGBA字节数组:CGColorSpaceRefcolorSpace=CGColorSpaceCreateDeviceRGB();CGContextRefcontext=CGBitmapContextCreate(bytes,width,height,8,4*width,colorSpace,kCGImageAlphaPremultipliedLast);CFRelease(colorSpace);CGImageRefcgImage=CGBitmapContextCreateImage(context);CGContextRel

swift - 类型 'NSLinguisticTag' 的值没有成员 'range'

我有文本方向代码,它在swift3上运行良好,但在迁移到swift4后,出现错误lettagScheme=[NSLinguisticTagScheme.language]lettagger=NSLinguisticTagger(tagSchemes:tagScheme,options:0)tagger.string=self.textletlang=tagger.tag(at:0,scheme:NSLinguisticTagScheme.language,tokenRange:nil,sentenceRange:nil)iflang?.range(of:"he")!=nil||lang

swift - 无法将类型 'NSRange'(又名 'NSRange')的值转换为预期参数类型 'Range<Index>'(又名 'Range<Int>')

我正在尝试实现EasyGameCenterlink但我得到这个错误:Cannotconvertvalueoftype'NSRange'(aka'NSRange')toexpectedargumenttype'Range'(aka'Range')代码如下:staticfuncunarchive(_data:Data!)->Packet{vararchivedPacket=ArchivedPacket(index:0,numberOfPackets:0,nameLength:0)//,dataLength:0letarchivedStructLength=sizeof(ArchivedPa

ios - 为什么 Swift 打印 "Optional(455 bytes)"

我正在开发一个天气应用程序,并尝试从API获取数据。但是,当我输入城市名称并按回车键时,Swift会打印出一条消息“可选(455字节)”,不知道出了什么问题。importFoundationprotocolWeatherServiceDelegate{funcsetWeather(weather:Weather)}classWeatherService{vardelegate:WeatherServiceDelegate?funcgetWeather(city:String){letpath="http://api.openweathermap.org/data/2.5/weather

ios - 错误 : "array index out of range" in multidimensional array

我已经声明了我的数组vartile=[[Int]]()然后我像初始化它的值一样for(varindex=0;index运行时报错“数组索引超出范围” 最佳答案 正如评论员@C_X和@MartinR所说,您的数组是空的。以下是如何根据需要对其进行初始化...vartile=[[Int]](count:4,repeatedValue:[Int](count:4,repeatedValue:0))forindexin0.....当然,for循环现在是多余的,如果您只想要零! 关于ios-错误: