草庐IT

Duck-typing

全部标签

swift - PromiseKit 无法将类型 '[Result<TYPE>]' 的值分配给类型 '[TYPE]

使用PromiseKit,我试图将whenblock的输出设置为局部变量allChatRoomsvarallChatRooms:[ChatRoom]varchatRoomIDs:[String:Bool]=...firstly{when(resolved:chatRoomIDs.map{fetchChatRoom(id:$0.key)})}.then{chatRooms->VoidinallChatRooms=chatRooms编译器错误是:注意:(ChatRoom和KChatRoom是一样的)如何将结果设置为allChatRooms变量? 最佳答案

json - swift 4 : how to implement codable protocol for json array of different types

有人可以启发我如何为以下多种类型的json数组实现codableprotocol到swift结构吗?在下面的json素材数组中,可以是反射对象、视频对象或笔记对象。{"materials":[{"reflection":{"title":"3-2-1reflection","description":"pleasereflectaftertoday","questions":[{"question":"question1","answer":"answer1","answerImageUrl":"http://xxx"},{"question":"question1","answer"

ios - 初始化 CBCentralManager : Type of expression is ambiguous without more context

尝试在Swift4.2项目中初始化CBCentralManager。获取评论中显示的错误:importCoreBluetoothclassSomeClass:NSObject,CBCentralManagerDelegate{//Typeofexpressionisambiguouswithoutmorecontextletmanager:CBCentralManager=CBCentralManager(delegate:self,queue:nil)//MARK:-Functions:CBCentralManagerDelegatefunccentralManagerDidUpda

objective-c - CGFLOAT_TYPE 和 swift

我的情况:我学习Swift有一段时间了,Swift是我唯一学过的iOS开发语言,这意味着我没有系统地学习Objective-C。我只能读一点OC代码。当我尝试将OC项目转换为Swift项目时遇到了类型转换问题。我只是对那个OC代码中的一些Type感到困惑。Objective-C代码:staticinlineCGFLOAT_TYPECGFloat_ceil(CGFLOAT_TYPEcgfloat){#ifCGFLOAT_IS_DOUBLEreturnceil(cgfloat);#elsereturnceilf(cgfloat);#endif}我未经证实的猜测:我认为这是一个函数,可以完成

ios - 不清楚的 "Type of expression is ambiguous without more context"错误

几个月后我回到我的旧XCode项目,现在我有很多以前没有的错误,我假设这与更新的语法有关。为什么我会看到:Typeofexpressionisambiguouswithoutmorecontext对于这个block@IBActionfuncsubmitUrl(sender:UIButton){varapp=UIApplication.sharedApplication().delegateas!AppDelegate//ErroroccursinbelowdeclarationofstudentDictvarstudentDict=["latitude":self.latitude,"

ios - swift 2 : Binary operator '==' cannot be applied to operands of type '()?' and 'Bool'

在我更新Xcode7beta并将我的swift代码转换为Swift2之后,我遇到了这两个我无法弄清楚的错误。Callcanthrow,butitisnotmarkedwith'try'andtheerrorisnothandledBinaryoperator'=='cannotbeappliedtooperandsoftype'()?'and'Bool'我的代码在这里。ifself.socket?.connectToHost(host,onPort:port,viaInterface:interfaceName,withTimeout:10)==true{//connecting}el

ios - Swift 2.0 - "Cannot convert return expression of type ' NSURL' 返回类型 'String' "

我正在尝试将旧的swift应用程序转换为2.0,但似乎无法通过此函数中的这段代码:funcdocumentsPathForFileName(name:String)->String{letpaths=NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true);letpath=paths[0];letfullPath=NSURL(fileURLWithPath:NSTemporaryDirectory()).URLByAppendingPathComponent(name)returnfullP

swift - 将元组作为 inout 参数传递时出现 "implicit conversion from <tuple type> to <tuple type 2> requires a temporary"错误

这是我的代码:varmyTuple=("bar",42)funcfoo(_bar:inout(arg1:String,arg2:Double)){[...]}foo(&myTuple)我收到此行的以下错误:foo(&myTuple)Cannotpassimmutablevalueasinoutargument:implicitconversionfrom'(String,Double)'to'(arg1:String,arg2:Double)'requiresatemporary 最佳答案 实际问题是您的元组变量缺少函数中存在的标签

ios - 错误 : Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePickerController.InfoKey'

这个问题在这里已经有了答案:Cannotsubscriptavalueoftype'[String:Any]'withanindexoftype'UIImagePickerController.InfoKey'(8个答案)关闭3年前。我正在尝试通过CoreML重建用于图像检测的Apple测试应用程序,但出现错误:Cannotsubscriptavalueoftype'[String:Any]'withanindexoftype'UIImagePickerController.InfoKeyextensionImageClassificationViewController:UIImag

ios - SwiftUI -> 线程 1 : Fatal error: No observable object of type MyObject. 找到类型(工作表中的 EnvironmentObject)

我正在使用SwiftUI构建应用程序。当我尝试显示工作表(以前是模态)时,出现此错误消息:Thread1:Fatalerror:NoobservableobjectoftypeBixiStationCombinedListViewModel.Typefound.AView.environmentObject(_:)forBixiStationCombinedListViewModel.Typemaybemissingasanancestorofthisview.当我使用@State变量显示包含使用MapKit的MapView的模态时,会发生此错误。我不明白为什么以及如何实现一个新的环境