草庐IT

subscription

全部标签

swift - "subscript"的使用不明确

我在尝试使用下标访问范围的第n个元素时遇到问题。代码super简单:varrange=0..第二行提示错误Ambiguoususeof"subscript",我的意思是Xcode不清楚变量range的类型是什么,所以它无法知道要使用subscript的哪个实现。我试图通过用显式定义range的类型来解决这个问题varrange:Range=0..和varfirstInRange=(rangeasRange)[0]但是这些都没有解决问题。有没有办法让Xcode消除对subscript的调用的歧义? 最佳答案 您可以创建一个包含范围的数

ios - 错误 : Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePickerController.InfoKey'

这个问题在这里已经有了答案:Cannotsubscriptavalueoftype'[String:Any]'withanindexoftype'UIImagePickerController.InfoKey'(8个答案)关闭3年前。我正在尝试通过CoreML重建用于图像检测的Apple测试应用程序,但出现错误:Cannotsubscriptavalueoftype'[String:Any]'withanindexoftype'UIImagePickerController.InfoKeyextensionImageClassificationViewController:UIImag

ios - fatal error : subscript: subRange extends past String end Xcode

我正在构建一个同时使用firebase和parse的应用程序,由于某种原因我不断收到fatalerror:fatalerror:subscript:subRangeextendspastStringend不知道为什么我一直收到这个;/我尝试进行搜索,但一无所获。谢谢。 最佳答案 它有点类似于“数组索引超出范围”,但对于字符串。letstr="qwertyui"varstr1="qwer"//length=4letind=advance(str.startIndex,6)//equals6str1[ind]//fatalerror:s

arrays - 数组扩展,对成员 'subscript' 的引用不明确

我正在尝试在Xcode的playground中编写Array的扩展。我想编写一个函数来修改数组,以便在调用该函数时用0填充它。我尝试使用的代码是这样的:importFoundationextensionArray{mutatingfunczero(){foriin0..此代码无法运行,因为错误位于:self[i]=0但是,如果我尝试从self中“获取”一个值,我没有任何问题。例如:importFoundationextensionArray{mutatingfunczero(){foriin0..没有错误并按预期运行。所以我的问题是;为什么我不能修改数组?此外,替换:self[i]=0

ios - swift 数组 : subscript with IndexPath - unable to mutate

我想为数组的数组添加一个扩展,以检索具有大小为2的IndexPath的Element:letarray:[[String]]=....letindexPath=IndexPath(indexes:[0,0])letstring=array[indexPath]我在实现以下扩展时遇到错误无法通过下标分配下标是只获取:extensionArraywhereElement:Collection,Element.Index==Int{subscript(indexPath:IndexPath)->Element.Iterator.Element{get{returnself[indexPath

ios - Swift 编译器 : cannot subscript a value of type '[NSObject]' with an index of type '()'

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭7年前。Improvethisquestion场景:第1步:第2步:第3步:问题总结:我开始使用swift及其基本概念。首先,我尝试用多个不同类型的元素制作一个数组ab(不确定它是否应该被称为数组)。然后我尝试测试一个索引值ab[2]。成功测试索引值后,我制作了一个字典dictAbc,其中我使用不同的索引ab[4]ab[6]指向到它的键。它引入

ios - swift 2 : Cannot subscript a value of type '[GKScore]?'

让highscore=leaderboardRequest.scores[0]为!GKScore结果为无法下标“[GKScore]”类型的值?Swift2中正确的语法是什么 最佳答案 leaderboardRequest.scores未解包,使用下标前解包。ifletscores=leaderboardRequest.scores{iflethighscore=scores.firstas?GKScore{//safelyuse`highscore`here}}“展开”是Swift中的一个关键概念,它与Optionals一起出现。[

Swift 3 升级 : Type 'Dictionary<NSObject, AnyObject>?' has no subscript members

我最近将我的应用程序从Swift2.3升级到Swift3.0,当我这样做时,我收到以下错误:Type'Dictionary?'hasnosubscriptmembers它出现的函数如下:classfuncgetSSIDConnectionName()->String?{varcurrentSSID:String?letinterfaces=CNCopySupportedInterfaces()ifinterfaces==nil{print("Gotniluphere")returnnil}letinterfaces2:CFArray!=interfacesforiin0..我在“cur

ios - 适用于 iOS 的 Google 登录 : error "Cannot subscript a value of type ' [String : AnyObject ]' with an index of type ' String'"

对于options[UIApplicationOpenURLOptionsSourceApplicationKey],“无法使用String类型的索引为类型[String,AnyObject]的值下标”。Swift2、iOS9.x、GoogleSignin使用CocoaPods安装。有什么提示吗?funcapplication(app:UIApplication,openURLurl:NSURL,options:[String:AnyObject])->Bool{returnGIDSignIn.sharedInstance().handleURL(url,sourceApplicati

arrays - swift 错误 "Cannot subscript a value of type [Uint8]"

大约过去一个小时我一直在为这个问题困惑,我的头发都快没了。我在AdventOfCode.com第4天玩得很开心(10月10日,会再次玩)并希望这个小功能起作用。(请不要评论我的代码不是多么漂亮。这意味着快速和肮脏,但现在只是肮脏。哎呀,我什至不知道代码是否有机会工作。任何人...)funccountDigestLeadingZeros(theDigest:[UInt8])->Int{vartheCount:Int=0print(theDigest[0])while((theCount0)){theCount++}returntheCount}错误发生在theDigest[theCoun