草庐IT

subscript

全部标签

ios - '子字符串(来自 : )' is deprecated: Please use String slicing subscript with a ' partial range from' operator. Swift 4 错误

这个问题在这里已经有了答案:HowcanIuseStringsubstringinSwift4?'substring(to:)'isdeprecated:PleaseuseStringslicingsubscriptwitha'partialrangefrom'operator(21个答案)关闭5年前。我正在将我现有的应用程序从Swift3转换为Swift4。它给出了错误:'substring(from:)'isdeprecated:PleaseuseStringslicingsubscriptwitha'partialrangefrom'operator.和'characters'i

swift - 无法通过下标分配给 Swift String

我有一个包含名称、图像、名称的虚线形式和名称长度的类。例如,我可以有“狗”、一张狗的图像、“---”和名称长度3。我只想为每个对象设置名称和图片,并自动设置dashName和nameLength。classAnswer{varname="name"varimage:UIImage?vardashName="name"varnameLength=0init(){vara=0nameLength=name.characters.countwhilea问题是这样的错误:“无法通过下标赋值:下标是只获取”和另一个错误:“下标不可用:不能用Int下标字符串” 最佳答案

swift - "Unwrapping"从 Firebase 检索到的数据

所以我设法从Firebase中检索了一些data,打印时看起来像这样:[Resturant.CustomerList(key:"-LQQlhEmNZb8Kaha9uCk",customerLastName:“Kendrick”,customerFirstName:“Anna”,customerSeat:"100",customerOrder:“Noodle”,Timestamp:1541290545703.0)]问题:如何解包它们以便将单个值放入其他String变量中?我尝试了很多方法,但出现错误,例如如果我执行类似letcustName=self的操作,则无法使用String类型的索

ios - 使用 FBSDKApplicationDelegate 时对成员 'subscript' 的引用不明确

我已经更新了swift3,我发现了很多错误。这是其中之一:Ambiguousreferencetomember'subscript'对于下一行funcapplication(_app:UIApplication,openurl:URL,options:[UIApplicationOpenURLOptionsKey:Any])->Bool{FBSDKApplicationDelegate.sharedInstance().application(app,open:url,sourceApplication:options["UIApplicationOpenURLOptionsSourc

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 - 重载字典下标两次并转发调用

我正在尝试扩展Dictionary并允许提取转换为特定类型并具有给定默认值的值。为此,我为subscript函数添加了两个重载,一个有默认值,一个没有:extensionDictionary{subscript(_key:Key,astype:T.Type,defaultValue:T?)->T?{//theactualfunctionismorecomplexthanthis:)returnnil}subscript(_key:Key,astype:T.Type)->T?{//thefollowinglineerrorsout://Extraneousargumentlabel'de

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

arrays - 快速访问数组中的字典值

我有一个数组,其中包含我的TableView部分的数据letmenuItems:Dictionary>[]=[["data":["name":"test","image":"test.png"]],["data":["name":"test2","image":"test2.png"]]]我正在尝试使用下标访问它functableView(tableView:UITableView!,titleForHeaderInSectionsection:Int)->String!{returnmenuItems[section]["data"]["name"]}出现错误Couldnotfind