草庐IT

int_void

全部标签

xcode - 无法使用类型为 'getDataInBackgroundWithBlock' 的参数列表调用 '((NSData!, NSError!) -> Void)'

我正在使用swift6.3并且有2个类似的错误无法使用类型为“(([AnyObject]!,NSError!)->Void)”的参数列表调用“findObjectsInBackgroundWithBlock”无法使用类型为“((NSData!,NSError!)->Void)”的参数列表调用“getDataInBackgroundWithBlock”有什么想法吗?importParseimportUIKitclassUserVC:UIViewController,UITableViewDataSource,UITableViewDelegate{@IBOutletvarresultTa

swift - 无法在通用实现中将 [Int] 转换为 [Int]

我在尝试创建通用数据源时遇到了这个错误,我想知道为什么它不可编译。错误:无法将类型“[Int]”的返回表达式转换为返回类型“[Int]”代码:protocolDataSource{funcgetData()->[T]}classIntDataSource:DataSource{letdata:[Int]=[]funcgetData()->[Int]{returndata}}IntDataSource中的return语句抛出错误。我知道这可以用更好的方式完成typealiasDataTypevardata:DataType?{get}但我主要感兴趣的是为什么编译器不想接受返回语句。有什么

ios - 如何在 Swift 中将 RealmOptional 转换为 Int 或 Float?

我想转换定义为RealmOptional的类型到Int或Float,取决于分配给泛型的类型。但是,当我尝试使用switch分发它们时声明,结果不是RealmOptional()但是RealmOptional()被分类为Int个案。例如,switchvalue{//valueisoftypeAnyObject?caseisString:cell.valueLabel.text=valueas?StringcaseisInt://RealmOptionalareexecutedhereletv=valueas!Intcell.valueLabel.text=String(v)//Float

swift - 如何将 Int16 音频样本数据转换为浮点音频样本数组

我目前正在处理音频样本。我从AVAssetReader得到它们,并有一个CMSampleBuffer像这样:guardletsampleBuffer=readerOutput.copyNextSampleBuffer()else{guardreader.status==.completedelse{returnnil}//Completed//samplesisanarrayofInt16letsamples=sampleData.withUnsafeBytes{Array(UnsafeBufferPointer(start:$0,count:sampleData.count/Memo

swift - 字符串之间有什么不同(描述: Int) vs String(Int)?

我需要将Integer值转换为String。我用Integer值创建了一个变量,然后我使用print打印了它。以下方法有何不同?varword="Countis"varcount=100print(word+String(describing:count));//Countis100print(word+String(count));//Countis100 最佳答案 你的问题实际上是不必要的,因为如果所有你想在这里做的是打印,你可以直接这样做:print("Countis",count)//Countis100那是因为print采

string - 将字符串转换为 int8 数组

我有一个包含C字符串的C结构(旧库,等等等等),现在我需要将CFString和Swift字符串转换成这个C字符串。有点像structProduct{charname[50];charcode[20];}所以我试图将其分配为productName.getCString(&myVarOfStructProduct.name,maxLength:50,encoding:NSUTF8StringEncoding)但是编译器给我以下错误:无法将类型(int8,int8,int8....)转换为[CChar]。 最佳答案 可能的解决方案:wit

objective-c - Swift 中的 Unsigned Int 到负 Int

我正在处理Pebble加速度计数据,需要将负整数的无符号表示形式转换为正常数字(例如,请注意前两个)。[X:4294967241,Z:4294967202,Y:22][X:4294967278,Z:4294967270,Y:46][X:4294967274,Z:4294967278,Y:26][X:4294967221,Z:85,Y:4294967280][X:4294967247,Z:117,Y:4294967266]使用ObjectiveC,我已经设法通过简单的[numberintValue]做到了这一点。但是,使用Swift我找不到这样做的方法。我试过Int(number),但我

ios - iPhone 5 和 iPhone 6 中的不同 Int 类型

我正在将一个静态的整数流读入一个整数数组:funccreate_int_array_from_nsmutable(nsdata:NSMutableData)->[Int]{letpointer=UnsafePointer(nsdata.bytes)letcount=nsdata.length/sizeof(Int);//Getbufferpointerandmakeanarrayoutofitletbuffer=UnsafeBufferPointer(start:pointer,count:count)letarray=[Int](buffer)returnarray;}现在我意识到,

ios - 类型为 Void 的 appendAttributedString 返回值

我正在尝试附加两个NSAttributedString。letstring_1:NSAttributedString=self.answerTextView.attributedTextletstring_2:NSAttributedString=handleHtml(i)//afunctionthatreturnsaNSAttributedStringletfinalStr:NSAttributedString=string_1.mutableCopy().appendAttributedString(string_2)但是我在第三行报错了:Cannotconvertvalueoft

arrays - 生成具有 Int 范围的特定 float 组

我想生成一个数组,其中包含所有整数和具有Int范围的.5值。想要的结果:最小值=0最大值=5生成的数组=[0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5]我知道如何只获取整数值:数组(0...5)但不是这个有浮点值的......我认为已经足够清楚了,有人有想法吗? 最佳答案 使用Array()和stride(from:through:by:):letarr=Array(stride(from:0,through:5,by:0.5))print(arr)[0.0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,