草庐IT

invokable

全部标签

ios - 数组扩展泛型 Equatable - "Cannot invoke ' = =' with ..."

我正在尝试编写Swift数组的扩展,但在尝试编译时出现了一些奇怪的错误。我的代码:extensionArray{funcitemExists(item:T)->Bool{foreltinself{ifelt==item{returntrue}}returnfalse}}错误:Cannotinvoke'=='withanargumentlistoftype'(T,T)'为什么我会收到这个?我正在使用Equatable协议(protocol)?我也试过的是:extensionArray{funcitemExists(item:T)->Bool{vararray:[T]=selfforelt

swift - 整数类型 : Cannot invoke 'init' with an argument of type 'T'

我有一个返回范围内整数的函数:funcrandomNumber(min:T,max:T)->T{letn=max-min+1letu=UInt32(n)//Error:Cannotinvoke'init'withanargumentoftype'T'letr=arc4random_uniform(u)returnr+min}我不明白为什么这不起作用,因为UInt32最上面的协议(protocol)是UnsignedIntegerType,它符合IntegerType。我必须将n变成UInt32因为arc4random_uniform()需要一个UInt32作为参数为什么这行不通?

ios - 无法使用 Google Places API 获取地点的详细信息 - "Cannot invoke ' lookUpPlaceID' "

我正在尝试使用适用于iOS的GooglePlacesAPI获取有关地点的详细信息。尝试调用lookUpPlaceID函数时,收到以下Swift编译器错误:Cannotinvoke'lookUpPlaceID'withanargumentlistoftype'(String,callback:(GMSPlace!,_)->Void)'letplaceID="ChIJV4k8_9UodTERU5KXbkYpSYs"placesClient!.lookUpPlaceID(placeID,callback:{(place:GMSPlace!,error)->Voidiniferror!=nil

Swift 2.0 : Cannot invoke with an argument list of type. ..(HTTP 请求)

自从我升级到Xcode7beta后,我遇到了一个无法修复的错误。这是我的DataManager.swift中的完整代码importFoundationvarTopAppURL:String=String()varnumberAsked:String=String()classDataManager{classfuncgetInfo(ID:String){TopAppURL="http://sweetapi.com/?=\(ID)"numberAsked=ID}classfuncloadDataFromURL(url:NSURL,completion:(data:NSData?,erro

ios - 在 Swift 数组上使用过滤器会给出 "cannot invoke filter with an argument list of type (Object) throws -> Bool,"但参数不会抛出

我无法确切地弄清楚Swift在这里期望什么样的参数列表,因为当我在swift数组上调用“filter”时出现错误。这是我的代码:funcsetDefaultBook(){varbook:BookletfetchRequest:NSFetchRequest=Book.fetchRequest()ifletfetchResults=try?managedObjectContext.fetch(fetchRequest){book=fetchResults.filter{$0.title==defaultBookTitle}}...}一本书是一个NSManagedObject,一本书的标题是

ios - 带有类型为 "cannot invoke initializer for type ' 的参数列表的 'UITextField' Int' 是什么意思?

在我的应用程序中,我有一串代码是lrs24=(30*Int(weight)!+70)*Int(factor)!;。看起来一切正常,但编译器说它“无法使用类型为‘UITextField’的参数列表为类型‘Int’调用初始化程序”。这是什么意思,我该如何解决?谢谢!PS-这是所有我的代码-importUIKitclassViewController:UIViewController,UITextFieldDelegate{@IBOutletweakvaranimalNum:UITextField!@IBOutletweakvarlogLabel:UILabel!@IBOutletweakv

Swift 的步幅(从 : , 到 : , 由:)导致 "cannot invoke"

我是第一次使用Swift的步幅。但是,由于我无法使其正常工作,因此first即将成为最后一个:letboundingBox=createdShape.frame//=SKShapeNodestride(from:Int(boundingBox.minX),to:Int(boundingBox.maxX),by:10){结果是:Cannotinvoke'stride'withanargumentlistoftype'(from:Int,to:Int,by:Int,()->())'我做错了什么? 最佳答案 语法应该是:letboundi

swift - 如何在 Swift 5.1 中修复 "Cannot invoke ' 无参数发送'

我一直在努力关注“介绍SwiftUI-构建您的第一个应用程序”WWDC19视频。本次演讲没有提供示例代码,但我一直在随着演示者的进行而创建它。虽然我在尝试创建商店时收到错误消息,即“无法在没有参数的情况下调用‘发送’”:didSet{didChange.send()}我是编程新手,正在努力解决问题。importSwiftUIimportCombineclassReferenceStore:BindableObject{varreferences:[Reference]{didSet{didChange.send()}}init(references:[Reference]=[]){se

ios - 切换 map : error: cannot invoke 'map' with an argument list of type '((_) -> _)'

我不明白为什么这个有效:vararr=[4,5,6,7]arr.map(){xinreturnx+2}虽然这个不是arr.map(){xinvary=x+2returny}有错误Playgroundexecutionfailed:MyPlayground.playground:13:5:error:cannotinvoke'map'withanargumentlistoftype'((_)->_)'arr.map(){ 最佳答案 这里的问题是有错误信息。通常,当您看到类似cannotinvoke..with...的内容时,这意味着编

swift - 高阶函数 : "Cannot invoke ' map' with an argument list of type '((_) -> _)' "

我想使用快速的高阶函数(映射)从给定的UIView.subviews数组中删除所有subview。线路(cell.contentView.subviewsas[UIView]).map{$0.removeFromSuperView()}导致错误“无法使用类型为‘((_)->_)’的参数列表调用‘map’”此时我想知道编译器需要我做什么。 最佳答案 我会说map不适合这种操作。它基于其他序列元素创建一个新序列,但您不想创建一个序列,您只想遍历它们并对它们应用一个函数。在swift中,没有满足您需求的高阶函数,我希望他们能尽快加入一些东