草庐IT

initial_value

全部标签

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 类中的自定义初始化给出 'property not initialized at implicitly generated super.init call' 错误?

我正在尝试创建一个简单的类用作我的MKMapView的注释。我正在获取要解析到这些注释对象中的数据,并认为用字典初始化注释是个好主意,并在这个模型类中而不是在UIViewController。不过,我似乎无法摆脱编译器错误,每当我尝试修复一个错误时,就会出现另一个错误。当前正在获取未在隐式生成的super.init调用中初始化的“属性self.coordinate”。调用super.init()只会产生不同的错误“Propertyself.coordinatenotinitializedatsuper.initcall”,无论我在哪里在方法中调用super.init()。任何帮助将非常

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]{

ios - Swift - NSIndex forRow inSection Initializer

我有以下代码:varpath=NSIndexPath(forRow:index,inSection:0);我收到一条编译器警告:调用中的额外参数“inSection”为什么?我在这里的文档中看到了初始化程序:https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSIndexPath_UIKitAdditions/index.html#//apple_ref/occ/clm/NSIndexPath/indexPathForRow:inSection:我导入了UIKit,甚至尝试做类似的事情:varpa

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.'我创建了

ios - swift 核心数据 : error: Failed to call designated initializer on NSManagedObject class 'NSManagedObject'

我正在使用核心数据在vc1中保存一个类别,并想将列表属性添加到vc2中的列表中。我的数据模型是许多列表属性的一个类别。我在vc1中添加这样的类别:funccreateNewCategory(){varcategory:NSManagedObject!=NSEntityDescription.insertNewObjectForEntityForName("Category",inManagedObjectContext:self.context)asNSManagedObjectcategory.setValue(self.categoryTextField.text,forKey:"

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