草庐IT

are_convertible

全部标签

swift 3 : Converting Data to String returns a nil value

将数据转换为字符串返回nil值。代码://thusunwrapstheimageifletimage=image{print("Savingimagedata")//don'tunwraphereifletdata=UIImagePNGRepresentation(image){letstr=String(data:data,encoding:.utf8)print(str)}}我不知道原因。另外,如何将字符串转换回数据? 最佳答案 这不起作用,因为当您将图像的字节解释为字符串时,该字符串无效。并非每个困惑的数据都是有效的utf8字

string - fatal error : high- and low-surrogate code points are not valid Unicode scalar values

这个问题在这里已经有了答案:HowcanIgeneratearandomunicodecharacterinSwift?(2个答案)关闭7年前。有时在用57292之类的值初始化UnicodeScalar时会产生以下错误:fatalerror:high-andlow-surrogatecodepointsarenotvalidUnicodescalarvalues这是什么错误,为什么会发生,以后我该如何预防?

swift - Rx swift : enable/disable button based on textfields are not empty

我必须使用RxSwift根据两个文本字段上的字符数启用一个按钮@IBOutletweakvaruserTextField:UITextField!@IBOutletweakvarpasswordTextField:UITextField!@IBOutletweakvarbuttonToEnableDisable:UIButton!varenabledObservable=combineLatest(userTextField.rx_text,passwordTextField.rx_text){(user,password)inself.loginButton.enabled=a.ch

ios - 以编程方式将自定义 UIViewcontroller 添加到 subview 但收到错误消息 "Cannot convert value of type..."

我正在尝试在Swift中以编程方式将自定义UIViewController类(UIPickerView)添加到我的主ViewController(不使用Storyboard)但我收到以下错误消息..."Cannotconvertvalueoftype'HabitViewViewController'toexpectedargumenttype'UIView'自定义UIPicker类:importUIKitclassHabitViewController:UIViewController,UIPickerViewDataSource,UIPickerViewDelegate{@IBOut

iphone - 为什么在将 Float 转换为 CGFloat 时 Xcode 给我一个警告 "Cannot convert value of type ' CGFloat' to expected argument type 'UnsafeMutablePointer"?

我正在尝试将Float值转换为CGFloat值,这里是我的代码:letmyFloatForR=0letr=CGFloat(myFloatForR)letmyFloatForG=0letg=CGFloat(myFloatForG)letmyFloatForB=0letb=CGFloat(myFloatForB)letmyFloatForA=0leta=CGFloat(myFloatForA)tintColor.getRed(r,green:&g,blue:&b,alpha:&a)但Xcode突然给我一个警告说:“无法将类型'CGFloat'的值转换为“tintColor”行上的预期参数类

string - '(NSObject, AnyObject )' is not convertible to ' 字符串'

如何将(NSObject,AnyObject)类型的对象转换为String类型?在下面方法的第一行末尾,asString导致编译错误:'(NSObject,AnyObject)'isnotconvertibleto'String'将street转换为NSString而不是String编译,但我正在将street转换为String因为我想将它与placemark.name进行比较,后者的类型为String!,而不是NSString。我知道name和street是可选的,但我假设它们现在不是nil因为所有的地方都从MKLocalSearch似乎有非零名称和街道。funcformatPlac

ios - swift : How to convert String to string with time format?

我的字符串值包括时间,格式为"HH:mm"(16:50)我必须将此值转换为"hh:mm"格式(04:50)作为SWIFT中的字符串我试过NSDateFormatter之类的lettimeFormat=NSDateFormatter()timeFormat.dateFormat="hh:mm"vardateFromStr=timeFormat.dateFromString("16:50")varstrFromDate=timeFormat.stringFromDate(dateFromStr)但它不起作用..请告诉任何解决方案。 最佳答案

ios - swift 2 : "Bool' is not convertible to 'BooleanLiteralConvertible'

我在XCode6中创建了一个应用程序。今天我下载了XCode7并将我的应用更新为Swift2。有很多错误,但现在只有一个我无法解决。我不知道为什么,但是Xcode不喜欢animated的任何Bool选项并显示此错误-'Bool'isnotconvertibleto'BooleanLiteralConvertible'(如果你看一下函数本身,你会发现,它恰好采用了animated的Bool)varstartVC=self.viewControllerAtIndex(indexImage)asContentViewControllervarviewControllers=NSArray(o

ios - "Attempt to delete row from section 1, but there are only 1 sections before update"

我正在尝试删除不符合for循环条件的行。但是,我收到错误消息:“尝试从第1部分删除第0行,但更新前只有1个部分。”我以前从未见过这个,也不确定为什么会收到它。我的代码:functableView(tableView:UITableView,cellForRowAtIndexPathindexPath:NSIndexPath)->UITableViewCell{letcell=theTableView.dequeueReusableCellWithIdentifier("MyCell")as!TableViewCellcell.titleLabel.text=titles[indexPa

swift - 错误 : Bool is not Convertible to Void:

我正在从Obj移动我的代码。C到SwiftC并尝试实现Twittersdk..但是,我收到一个错误...任何人都可以告诉我我做错了什么。请帮我解决这个问题。我花了2天的时间尝试了所有方法,但都不适合我。 最佳答案 您的代码块没有返回语句,因此编译器使用最后一条语句的结果UIApplication.sharedApplication().openURL(url)作为返回值,它是一个Bool而不是block签名中声明的Void。要解决这个问题,只需添加一个return语句:{(url:NSURL,oauthToken:String)->