草庐IT

Duck-typing

全部标签

android - 在 Kotlin 中无法 "findViewById"。收到错误 "Type inference failed"

当我尝试通过id查找RecycleView时出现以下错误。Error:-Typeinferencefailed:NotenoughinformationtoinferparameterT代码:classFirstRecycleViewExample:AppCompatActivity(){valdata=arrayListOf()overridefunonCreate(savedInstanceState:Bundle?){super.onCreate(savedInstanceState)setContentView(R.layout.first_recycleview)valrec

ios - swift 3 : expression pattern of type 'Int' cannot match values of type 'UnsafeMutableRawPointer'

我正在将一个应用程序迁移到Swift3,但Xcode对此函数抛出错误:错误是在casecondition("contentSize",MyObservationContext)我这样做是为了更新uiwebview的内容大小varMyObservationContext=0overridefuncobserveValue(forKeyPathkeyPath:String?,ofobject:Any?,change:[NSKeyValueChangeKey:Any]?,context:UnsafeMutableRawPointer?){guardletkeyPath=keyPathelse

ios - 参数类型 'customClass.Type' 不符合预期类型 'NSItemProviderWriting'

iOS11.xswift4尝试实现自定义类以使用新的拖放协议(protocol)并需要一些super编码员的帮助。我创建了这个类。importUIKitimportMobileCoreServicesclassCustomClass:NSObject,NSItemProviderWriting,NSItemProviderReading{varimage2D:Data?staticvarreadableTypeIdentifiersForItemProvider=[kUTTypeDataasString]staticfuncobject(withItemProviderDatadata

swift - 参数类型 'T.Type' 不符合预期类型 'Comparable'

我试图在swift中创建一个小类,但得到以下错误参数类型T.TypedoesnotconformtoexpectedtypeComparable有人可以帮忙吗?structBST{letroot:Node?varcount=0init(data:T){self.root=Node(data:T)//ErrorOccursinthisline}}//endclassBST这是Node类的代码。classNode{letdata:Tvarleft:Node?varright:Node?init(data:T){self.data=data}//endinit}//endclassnodef

iOS swift : Value of type 'NotificationCenter' has no member 'publisher'

我正在尝试将新的Combine框架与NotificationCenter一起使用,正如Apple在这段视频中所解释的那样:https://developer.apple.com/videos/play/wwdc2019/721/您可以在幻灯片21中找到它。看来我的项目没有读取Combineframeworkapi。importCombineimportFoundationlettrickNamePublisher=NotificationCenter.default.publisher(for:.newTrickDownloaded)我收到这个错误:“NotificationCente

ios - 代码 8 : Terminating with Uncaught exception of type NSException

我是新手,我遇到了这个错误,我到处查找,但找不到解决方案。非常感谢任何帮助!0CoreFoundation0x00000001102bb34b__exceptionPreprocess+1711libobjc.A.dylib0x000000010d61c21eobjc_exception_throw+482CoreFoundation0x00000001102bb299-[NSExceptionraise]+93Foundation0x000000010d12c2ff-[NSObject(NSKeyValueCoding)setValue:forKey:]+2914UIKit0x000

ios - Swift 3 Firebase - (setValue :) Cannot store object of type _SwiftValue at content

我已经多次看到这个问题被问到,但似乎无法弄清楚如何使用这些答案来解决我的代码中的问题。这是我当前使用的代码:ifletpostContent=postAlert.textFields?.first?.text{letpost=Post(content:postContent,addedByUser:"MaxKortge")letpostRef=self.dbRef.child(postContent.lowercased())postRef.setValue(post.toAnyObject())//errorhere}我假设控制台中的错误是指我在其中评论“这里有错误”的那一行。toA

ios - Swift - 导入 Objective-C 给出 "Unknown type name"

我正在做一个快速的项目,直到我需要This“模拟式时间选择器”。我下载了repo并使用Xcode6.4进行了尝试,它工作正常。但是当我开始将它转移到我的项目时,它要求我创建一个Bridging-Header,我创建了一个,同时我在桥接头中导入了.h文件。我的项目可以看到委托(delegate)方法,所以我认为它很好。但问题是,.m文件上的变量有这样的错误:但是如果你注意到,最后一个UIButton没有错误。您认为问题出在哪里? 最佳答案 放#import或@importUIKit;在出现这些错误的.h文件的最顶部

ios - swift 4 : Array for all types of Ints and Floating point numbers

我有一个程序可以处理所有类型的Ints和Floating指针值类型有没有一种方法可以创建数组来保存所有这些值?我尝试通过协议(protocol)来做到这一点,并用它们扩展Int和Double但没有成功,因为Swift中的协议(protocol)均等性限制(或类似的东西)protocolArrayStructValue:Comparable,Equatable{}extensionDouble:ArrayStructValue{}extensionInt:ArrayStructValue{} 最佳答案 如果你想在一个数组中有两种不同的

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。因此