草庐IT

values-ta

全部标签

swift - "Expression resolves to an unused l-value"与 "Expression is unused"

考虑以下代码:classFoo{letbar="Helloworld!"init(){self//Warning:Expressionoftype'Foo'isunusedself.bar//Error:Expressionresolvestoanunusedl-value}functest(){self.bar//Warning:Expressionoftype'String'isunused}}为什么消息不同,为什么只有一个错误?我明白它们的意思,只是不明白为什么编译器会以不同的方式处理它们。 最佳答案 编译器之所以在初始化程序

ios - swift 3 : What's the safest way to unwrap optional values coming from an array?

首先,我初始化变量以保存股票数据varapplePrice:String?vargooglePrice:String?vartwitterPrice:String?varteslaPrice:String?varsamsungPrice:String?varstockPrices=[String]()我从YQL中获取当前股票价格,并将这些值放入一个数组中funcstockFetcher(){Alamofire.request(stockUrl).responseJSON{(responseData)->Voidinif((responseData.result.value)!=nil)

arrays - swift 3 : Remove value in Array with Unknown index

我想在我的ShinobiDataGrid中实现多次点击。我有一个有数组的网格(["1","32",andmore])如果我单击网格,我会将其放入新数组self.arrayNr.append(currNr)。但我想检查并删除currNr是否已经存在于arrayNr中,它将从arrayNr中删除。我是新手,正在使用Swift3。我读了一些关于我的问题的问题,比如this和this但它不工作。我认为Swift2在处理String方面比Swift3更简单。有什么建议或答案对我有帮助吗? 最佳答案 您可以使用index(of来检查数组中是否存

ios - Swift 如何获取对象的 "pass by value"

我是Swift的新手。我创建了一个类(例如):classFraction{vara:Intinit(a:Int){self.a=a}functoString()->String{return"\(self.a)"}}我还在其他类函数中构建了一个:classfuncA_plusplus(f:Fraction){f.a++}然后在执行类中我写:varobject=Fraction(a:10)print("beforerunfunc="+object.toString())XXXclass.A_plusplus(object)print("afterranfunc="+object.toSt

ios - 错误 : Value of type string has no member componentsSeparatedByCharactersInSet

以下代码抛出以下错误:“字符串类型的值没有成员componentsSeparatedByCharactersInSet”此代码来自之前在swift版本1或2中运行但不再运行的另一个项目。importFoundationextensionString{funcsplit()->[String]{returnself.componentsSeparatedByCharactersInSet(CharacterSet.whitespaceAndNewlineCharacterSet()).filter({$0!=""});}}extensionArray{funcunique()->[T]{

swift +锁匠: Not storing value

我试图在游戏结束时存储一个值。我正在使用https://github.com/matthewpalmer/LocksmithupdateData方法。GithubRepo上说aswellasreplacingexistingdata,thiswritesdatatothekeychainifitdoesnotexistalreadytryLocksmith.updateData(["somekey":"anothervalue"],forUserAccount:"myUserAccount")这是我的:letdictionary=Locksmith.loadDataForUserAcc

ios - 由于未捕获的异常 'NSUnknownKeyException' 而终止应用程序,原因 : this class is not key value coding-compliant for the key Label2. '

这个问题在这里已经有了答案:Xcode-Howtofix'NSUnknownKeyException',reason:…thisclassisnotkeyvaluecoding-compliantforthekeyX"error?(78个答案)关闭5年前。这是我收到的确切错误消息:Terminatingappduetouncaughtexception'NSUnknownKeyException',reason:'[setValue:forUndefinedKey:]:thisclassisnotkeyvaluecoding-compliantforthekeyLabel2.'我创建了

element 的 el-cascader 组件获取级联选中label和value值

1. 多选时 获取 cascader级联选择器的label值    需要给el-cascader加ref用以获取值//级联选择器//方法handleChange(){consttextArr=[];constarr=this.$refs["refCascader"].getCheckedNodes();arr.forEach((i)=>{textArr.push(i.pathLabels);});console.log(textArr);}, 获取后的样式2.单选时获取 cascader级联选择器的值 //element级联选择器//methods方法handleChange(a){const

swift - "cannot call value of non-function type"尝试调用 max(_ :_:) function

我正在尝试调用max函数:max(x:T,y:T)。但是,当我键入max(2,3)时,我不断收到以下错误:error:cannotcallvalueofnon-functiontypeIntvara=max(2,3)我是初学者,从来没有遇到过使用类型“T”的函数签名。所以与使用max函数相关的线程以我的方式调用它(比如max(2,3))所以我不确定我哪里出错了。我正在寻找关于“T”的解释以及如何调用支持泛型类型的函数以及如何使max函数在比较整数时返回32和3. 最佳答案 问题(如you'veconfirmedinthecommen

swift - 错误 : value of type 'String' has no member 'Generator' in Swift

这个问题在这里已经有了答案:IteratethroughaStringSwift2.0(4个答案)关闭7年前。我在Swift中有这段代码:varpassword="MeetmeinSt.Louis"forcharacterinpassword{ifcharacter=="e"{print("foundane!")}else{}}抛出以下错误:valueoftype'String'hasnomember'Generator'inSwiftinline:forcharacterinpassword我试图在网上找到可能的错误,但我找不到(而且我是Swift的新手,并且试图通过语言的特性来导航