草庐IT

convert_encoding

全部标签

swift 3 : Int is not convertible to Bool in bitwise operation

不确定我在这里做错了什么,但这是破坏的微不足道的代码:if10&(1这给了我:'Int'isnotconvertibleto'Bool'怎么了? 最佳答案 不像在C中你可以写...if(x){}...这实际上是一个非零检查:if(x!=0){}您必须在Swift中测试bool条件。将!=0添加到您的语句中:if10&(1 关于swift3:IntisnotconvertibletoBoolinbitwiseoperation,我们在StackOverflow上找到一个类似的问题:

ios - Mach-O 链接器警告 : too many personality routines for compact unwind to encode

我刚刚升级我的项目以使用Swift1.2。我收到一个以前从未见过的新链接器警告。ld:警告:压缩展开的个性例程太多,无法编码。它没有提供有问题的文件或任何其他详细信息。我知道如何抑制此警告,但我想知道如何修复它。有什么想法吗?这与回答的其他问题不同,因为它们都解释了如何隐藏警告,没有一个解释如何实际解决问题。 最佳答案 是的。我刚刚遇到了同样的错误。我打算自己压制它-但我觉得这不是一个好主意。 关于ios-Mach-O链接器警告:toomanypersonalityroutinesfor

ios - Alamofire 4.0.0 : [String:String] is not convertible to [String : Any] & Request is ambiguous without more context

我正在将Alamofire更新到4.0.0Beta1并将XCode8更新到Beta6。首先,我得到了[String:String]isnotconvertibleto[String:Any]错误代码letparameter=["scope":"\(scope)","client":"\(clientId)"]Alamofire.request(link,withMethod:.POST,parameters:parameter,encoding:.json).responseJSON在我更改后将[String:Any]添加到参数中,错误消失但产生了新错误:Expressiontype'

json - 将未知的 Encodable 枚举值解码为默认值

我必须像这样反序列化JSON字符串:{"name":"JohnSmith","value":"someValue"}在Swift4中,“值”应该是一个枚举,整个对象是一个结构,如:structMyType{name:String?value:Value?}在未来的某个时候,可能会在后端添加新的枚举值,所以我认为有一些回退是明智的。我想我可以创建一个像这样的枚举enumValue{casesomeValuecasesomeOtherValuecaseunknown(value:String)}但我只是想不通如何反序列化该枚举并使其正常工作。以前我只是简单地使用了一个String枚举,但是

ios - swift 4 中的“UIImage ?' is not convertible to ' UIImage”问题

我正在尝试实现一个图像选择器。在委托(delegate)方法中,我收到以下错误。或这是我写的代码funcimagePickerController(_picker:UIImagePickerController,didFinishPickingMediaWithInfoinfo:[UIImagePickerController.InfoKey:Any]){varimage=info[.editedImage]as?UIImageifimage==nil{image=info[.originalImage]as?UIImage}simpleImagePicker!.dismiss(ani

ios - 准备 segue : Cannot convert value of type 'UIViewController' to specified type 'SecondViewController'

我知道我肯定在这里遗漏了一些明显的东西,但我似乎无法通过它的实际类型来引用目标ViewController。我按照以下步骤从头开始创建了一个新项目来对此进行测试:创建一个新的单View应用程序项目添加一个新的ViewController创建一个新类,子类化UIViewController,并将其命名为SecondViewController将这个新类设置为第二个ViewController的自定义类(现在它的标题是第二个ViewController)向第一个ViewController添加一个按钮,然后按住Ctrl键单击它到第二个ViewController,然后从ActionSegu

ios - swift 3.1 : Cannot convert value of type '(_) -> ()' error/Problems with closures

我升级到Swift3.1,我收到了一些新错误,这些错误似乎是3.1语法问题,因为在迁移之前它们不是问题。它们大多与闭包有关,如本例所示:letalert=UIAlertController(title:"Success",message:"Thanksforparticipatinginourraffle!",preferredStyle:UIAlertControllerStyle.alert)alert.addAction(UIAlertAction(title:"OK",style:.default,handler:{performSegue(withIdentifier:"to

swift - 错误 : Cannot convert value of type 'URL' to expected argument type 'String'

我在将URL转换为字符串时遇到问题。getScreenShotDirectory()路径是file:///Users/Pat/Desktop/。我的目标是将其转换为字符串,因此路径可以类似于/Users/Pat/Desktop/leturlString=getScreenShotDirectory()letpathURL=URL(string:getScreenShotDirectory())!//error如果需要,我很乐意提供更多代码。 最佳答案 看来您的getScreenShotDirectory()方法已经是一个URL。因此

json - JSONEncoder.encode 在 Swift 中抛出什么异常?

我最近在使用JSONEncoder.encode()(及其对应的JSONDecoder.decode()),标记在thedocumentation中。作为throws。不幸的是,文档没有详细说明此方法何时/如何/可能抛出什么。有人对此有任何见解吗?我问是因为我想知道这里的错误是否足够普遍以为此实现面向用户的错误处理。谢谢 最佳答案 JSONEncoder.encode()当您要编码的值之一无效时抛出EncodingError.invalidValue(例如Double.infinity如果NonConformingFloatEnco

struct - 错误 : 'Int' is not convertible to '@lvalue Float'

给定以下函数:funcgreatestCommonDenominator(first:Int,second:Int)->Int{returnsecond==0?first:greatestCommonDenominator(second,first%second)}还有一个包含以下内容的结构:structFraction{varnumerator:Intvardenominator:Intfuncreduce(){letgcd=greatestCommonDenominator(numerator,denominator)self.numerator/=gcdself.denomina