草庐IT

converts

全部标签

swift 2 : Cannot convert value of type '[NSObject : AnyObject]' to expected argument type '[String : AnyObject]'

我有一个用Swift1构建的项目。但是在自动转换为Swift2后,它显示错误:无法将类型'[NSObject:AnyObject]'的值转换为预期的参数类型'[String:AnyObject]'。函数代码:funccreateViewContainers()->NSDictionary{varcontainersDict=NSMutableDictionary()letitemsCount:Int=tabBar.items!.countasInt-1forindexin0...itemsCount{varviewContainer=createViewContainer()conta

swift - 错误 : cannot convert value of type '() -> ()' to closure result type 'String' using Swift + PromiseKit

我不熟悉Swift中的promise,并使用PromiseKit尝试在Playground上创建一个非常简单的响应并尝试使用它。我有以下代码:importUIKitimportPromiseKitfuncfoo(_error:Bool)->Promise{returnPromise{fulfill,rejectinif(!error){fulfill("foo")}else{reject(Error(domain:"",code:1,userInfo:nil))}}}foo(true).then{response->Stringin{print(response)}}但是我得到以下错误

ios - Realm iOS : Cannot Convert value of type 'Dogs.Type' to expected argument type 'T.Type'

这是我的DBManager.swiftimportRealmSwiftclassDBManager{classfuncgetAllDogs()->[Dog]{letrealm=try!Realm()//COMPILERERROR:CannotConvertvalueoftype'Dogs.Type'toexpectedargumenttype'T.Type'returnrealm.objects(Dog.self)}}这是我的Dog.swift:importFoundationimportRealmSwiftclassDog:Object{dynamicvarfirstName=""d

swift 错误 : cannot convert value of type 'Int32' to expected argument type 'Int32'

我正在尝试编写一对函数,将String转换为[UInt8]字节数组,然后再转换回来。作为[UInt8]->String函数的一部分,我试图将单个Int32转换为Character。letnum:Int32=5letchar=Character(_builtinUnicodeScalarLiteral:num)但是我遇到了这个奇怪的错误:error:cannotconvertvalueoftype'Int32'toexpectedargumenttype'Int32'letchar=Character(_builtinUnicodeScalarLiteral:num)^~~编辑:我设法使

swift 错误 : cannot convert value of type B to type A in coercion

我有一个泛型类A及其子类B:classA{letx:T1lety:T2init(_v1:T1,_v2:T2){self.x=v1self.y=v2}}classB:A{init(_v:T){super.init(v,v)}}我需要一个不同对象的集合,它们都属于A的子类:vararr=[A]()但是我不能将对象放入集合中,下面的代码会导致错误:lett=B(10)arr.append(tasA)错误是:cannotconvertvalueoftype'B'totype'A'(aka'A,protocol>')incoercion如何解决这个问题? 最佳答案

ios - Xcode - Swift 编译器错误 : cannot convert the expression's type 'Double' to type 'Double'

如何在swift中将标checkout口字符串转换为double字符串?我有一个计时器正在更新标签:labelOutletForSecondsCount.text。标签用字符串“0,00”初始化。我想将停止的timeString(我从我的计时器中获取)保存为变量中的Double,以便在某些计算中使用它。我认为这行代码应该这样做,但我得到以下“Swift编译器错误:无法将表达式的类型‘Double’转换为类型‘Double’”。vartimeStringIntoDoubleValue=(labelOutletForSecondsCount.textasNSString).doubleVa

具有约束关联类型错误 "Type is not convertible"的 Swift 协议(protocol)

我已经创建了2个具有关联类型的协议(protocol)。符合Reader的类型应该能够生成符合Value的类型的实例。复杂层来自符合Manager的类型应该能够生成具体的Reader实例,该实例生成特定类型的Value(Value1或Value2)。在我对Manager1的具体实现中,我希望它始终生成Reader1,后者又生成Value1的实例。谁能解释一下原因"Reader1isnotconvertibletoManagedReaderType?"当错误行更改为(暂时)返回nil时,所有编译都很好,但现在我无法实例化Reader1或Reader2。可以将以下内容粘贴到Playgrou

ios - 从 iOS 应用调用号码 : Cannot convert the expression's type 'Bool' to type 'NSURL!'

我想在iOS应用程序中制作一个调用按钮,该按钮会提示native调用弹出窗口,其中包含我提供的号码。这是我现在的代码:@IBActionfuncbtnCall(sender:AnyObject){UIApplication.sharedApplication().openURL(url:"tel://0000000000")}这是我遇到的错误:Cannotconverttheexpression'stype'Bool'totype'NSURL!' 最佳答案 openURL方法需要一个NSURL对象,而您正在那里传递一个字符串。这就是

Swift 泛型错误 : Cannot convert value of type 'Type<T>' to expected argument type 'Type<_>'

请考虑以下设置:protocolMyProcotol{}classMyModel:MyProcotol{}enumResult{casesuccess(value:T)casefailure}classTest{functest(completion:(Result)->Void){letmodel=MyModel()letresult=Result.success(value:model)completion(result)}}为什么我不能调用completion(result)?我收到此错误:无法将“Result”类型的值转换为预期的参数类型“Result”任何解决方法?

java - @Converter 注释类未被 jpa 自动检测到

@Converter(自JPA2.1起引入)似乎是将数据库值切换为我们希望在java代码中看到的值的一种非常方便的方法。但是,我无法使它正常工作。JPA似乎不知道我编写的转换器,并试图自行将值转换为适当的类。这是我写的代码:@Converter(autoApply=true)publicclassDateConverterimplementsAttributeConverter{@OverridepublicStringconvertToDatabaseColumn(Dateb){System.out.println("ConvertingtoDatabaseColumns");ret