草庐IT

member-hiding

全部标签

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 - SKAction.fadeOut(withDuration : 2. 0) 是从场景中移除节点还是仅将其移除 "hides"?

所以我正在制作游戏并淡出一个节点,但我不知道它是从场景中移除还是只是隐藏了。我想在完全相同的位置添加另一个节点,但我不想让节点相互重叠。letfadeOutAction=SKAction.fadeOut(withDuration:2.0)nodeToFadeOut.run(fadeOutAction)这很完美,但我不知道节点是否已从场景中移除。 最佳答案 这里有一些你可能会觉得有用的东西:)funcfadeAndRemove(node:SKNode){letfadeOutAction=SKAction.fadeOut(withDur

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 - swift : Hide button in subview

我试图在触发函数时在subview中隐藏UIButton。我对该层次结构有多个View:vartakePhotoButton:UIButton=UIButton.buttonWithType(UIButtonType.System)asUIButtontakePhotoButton.addTarget(self,action:"takePhoto",forControlEvents:UIControlEvents.TouchUpInside)varsavePhotoButton:UIButton=UIButton.buttonWithType(UIButtonType.System)a

swift 协议(protocol) : hiding some properties

我想为UITextView和UITextField创建一个trimmedText属性。这是我所做的:protocolTrimmedTextSupporting:class{var_text:String?{get}vartrimmedText:String{get}}extensionTrimmedTextSupporting{vartrimmedText:String{lettext=self._text??""returntext.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacter

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