草庐IT

member-enumeration

全部标签

swift - 从常量 : Ambiguous reference to member 'subscript' 获取值时出错

我正在使用enum和tuple以及枚举大小写的值。我无法从[String:String]常量中获取值。我不知道如何修复它,它必须是一个陷阱,但我不知道在哪里,因为key肯定是字符串:enumDictTypes:String{casesettingscaseoptionscaselocations}enumFileTypes:String{casejsoncasepList}funcgetCodebookUrlComponent()->String{varFileSpecs:(dictType:DictTypes,fileType:FileTypes,redownload:Bool)=(

swift - 带有嵌套类的 Swift 4 上的 "instance member cannot be used on type"错误

我有一个带有嵌套类的类。我试图从嵌套类中访问外部类的变量:classThing{varname:String?vart=Thong()classThong{funcprintMe(){print(name)//error:instancemember'name'cannotbeusedontype'Thing'}}}然而,这给了我以下错误:instancemember'name'cannotbeusedontype'Thing'有没有一种优雅的方法来规避这种情况?我希望嵌套类能够像闭包一样捕获词法范围。谢谢 最佳答案 你可以这样做c

swift - 在 Swift 3.0 中在 WhatsApp 上共享错误 : Contextual member 'urlHostAllowed' has no associated value

我刚刚将我的swift项目升级到swift3。我一直在使用下面的功能在Whatsapp上分享应用程序,但是我无法理解升级后出现的错误这是函数代码:funcshareOnWhatsapp(){leturlString="Greetings,\n\nThisistheXYZApplink,Ihopeyoufindituseful!\n\nhttp://itunes.apple.com/app/idxxxxxxxx"leturlStringEncoded=urlString.addingPercentEncoding(withAllowedCharacters:.urlHostAllowed

ios - enumerated() 常数时间 O(1) 是如何实现的?

我正在查看有关Array类型的enumerated()的文档,并注意到它说:Complexity:O(1)https://developer.apple.com/documentation/swift/array/1687832-enumerated这似乎没有意义,因为遍历数组的时间是线性的-O(n)-因为数组的长度是未知的。enumerated()必须遍历数组才能返回EnumeratedSequence。这个函数的常数时间复杂度如何? 最佳答案 创建一个EnumeratedSequence归结为initializing它的迭代器。

swift - 在 Swift 中获取错误 Ambiguous reference to member 'subscript'

字典需要扩展以获取文本键值(如果存在)。执行以下代码并成功编译:extensionDictionarywhereKey:ExpressibleByStringLiteral,Value:AnyObject{funcgetValueForKeyPath(keyValue:String)->String{return((self["item_qty"]as?Dictionary)??["":""])?["text"]??""}}但是当我对方法做一些小改动时,出现错误:"Ambiguousreferencetomember'subscript'"extensionDictionarywher

ios - "Type ' 任务。在 Swift 中键入 ' has no subscript members"错误

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭6年前。Improvethisquestion这段代码给我一个错误;类型'task.Type'没有下标成员这是我的代码:structtask{varname="Un-Named"vardesc="Un-Described"}classTaskManager:NSObject{vartasks=task[]()funcaddTask(name:S

ios - 使用 Array 而不是 NSArray 时出现错误 "ambiguous reference to member subscript"

当我尝试访问数组类型值然后出现错误时,我在可能包含数组类型值的字典中收到类似“对成员下标的模糊引用”的错误。请检查以下代码。varoccupations=["Malcolm":"Captain","Kaylee":"Mechanic","Layme":["Engineer","Docter"]]as[String:Any]occupations["Jayne"]="PublicRelations"vararrOfLayme=occupations["Layme"]as!Array//gettingerrorhere,IfIuseNSArrayinsteadofarrayallwillw

ios - 无法使用类型为 'enumerate' 的参数列表调用 '(String)'

当我遵循NeilNorth的iOSSwift游戏教程时,出现错误“无法使用类型为‘(String)’的参数列表调用‘enumerate’”。这与1.2中的某种旧方法有关吗?有什么想法吗?convenienceinit(atlasName:String,tileSize:CGSize,tileCodes:[String]){self.init(tileSize:tileSize,gridSize:CGSize(width:tileCodes[0].characters.count,height:tileCodes.count))atlas=SKTextureAtlas(named:atl

ios - swift 错误 : Value of type 'NSObject -> () ' AnimalListTableViewController' has no member 'tableView'

我正试图在swiftxcode中消除这些错误如果截图太小,这里是代码importUIKitclassAnimalListTableViewController:UITableViewController{overridefunctableView(tableView:UITableView,numberOfRowsInSectionsection:Int)->Int{return4}letindexPath=self.tableView.indexPathForSelectedRow()//thisiswheretheerrorappears,itsaysValueoftype'NSO

ios - 初始化变量 : 'self' captured by a closure before all members were initialized

我在初始化自定义类时遇到问题。当初始化更新属性的类时,我需要在一些数据上设置一个观察者。最初,属性可以为空,这就是我在启动时设置它们的方式。但是,Xcode仍然会抛出“在所有成员初始化之前由闭包捕获的‘self’”错误。这是代码的简化版本。classFoo{init(){self.usersRef=ref.child("users")self.usersRef.observe(DataEventType.value,with:{(snapshot)in//snapshoterrorchecking//usersis[String]self.users=users})}privateva