草庐IT

current_index

全部标签

arrays - "fatal error: Array index out of range swift"

代码为:classSingleton{classvarsharedInstance:Singleton{structStatic{staticvarinstance:Singleton?=nilstaticvartoken:dispatch_once_t=0}dispatch_once(&Static.token){Static.instance=Singleton()}returnStatic.instance!}varprayerArray=Array()}和:overridefunctableView(tableView:UITableView,didSelectRowAtInd

ios - 在 Realm 中编辑属性后删除对象引发 RLMException 原因 : 'Index 0 is out of bounds (must be less than 0)'

我正在制作一个简单的应用程序,用户可以在其中使用数据库的swift和realm添加习惯和完成主题一切正常,除了我编辑状态和删除对象时应用程序因RLMException原因而崩溃:“索引0超出范围(必须小于0)”我注意到只有当该项目是tableView中唯一的单元格时才会发生这种情况如果有人能帮我解决这个问题,我将不胜感激,因为我一整天都在为此苦苦挣扎习惯对象是:classHabit:Object{dynamicvarid=0dynamicvarname=""dynamicvarstate=""convenienceinit(name:String){self.init()self.id

objective-c - 一些for循环的问题 - - "Cannot subscript a value of type ' Double' with an index of type 'int' "errors

我在有索引的地方收到很多“无法使用‘int’类型的索引下标‘Double’类型的值”错误?阵列?像这样此代码取自Obj-C,并尽可能翻译成Swift,但我不熟悉某些语法。我清理了for循环,但一些Obj-C语法仍然存在。你能帮我清理/重构我的代码吗?importUIKitimportFoundationimportAVFoundationletminFramesForFilterToSettle=10enumCurrentState{casestatePausedcasestateSampling}classViewController:UIViewController,AVCaptu

swift - UISearchController : how to get selected table row index in ios8 (Swift)

我知道searchDisplayController在ios8中已被弃用,我在使用UISearchController查找筛选结果中的选定行时遇到问题我有以下场景:varmyObject=PFObject(className:"XX")ifsegue.identifier=="XXXSegue"{ifletdestination=segue.destinationViewControlleras?XXXTableViewController{if(self.resultSearchController.active){ifletrow=self.searchDisplayControl

ios - swift - fatal error : Array index out of range

我正在尝试用每个增加0.1的数字填充一个数组,例如:[0.1,0.2,0.3...]此代码给我错误:fatalerror:数组索引超出范围。我错过了什么?我觉得我在声明错误。我会把它存成Double类型的结构。我的代码importUIKitclassPrecoDomicilioViewController:UIViewController,UIPickerViewDelegate,UIPickerViewDataSource{@IBOutletvareuros:UIPickerView!varpickerData:[Double]=[]overridefuncviewDidLoad()

swift - Swift 2.0 中的字符串索引 : How can I work around indexing a string?

我正在尝试获取字符串的内容:varoldString="hithis\tismy\tstring"oldString=String(oldString.componentsSeparatedByString("\t"))print(oldString[1])IgettheERROR:"'subscript'isunavailable:cannotsubscriptStringwithanInt..."如何访问包含在另一个字符串中的字符串?我想出的唯一方法是使用以下字符逐字符获取:forindexincontent.characters.indices{print(String(oldS

ios - swift 错误 : fatal error: Cannot index empty buffer

我是Swift语言的新手。我创建了一个MapKit应用程序,它从Sqlite数据库(最新的FMDB堆栈)中递归地检索MKPointAnnotation数据(纬度、日志和标题)。目的是把一堆兴趣点放在一个MKMapViewDelegate上。我尝试过不使用数组,但mapView.addAnnotation会覆盖任何点并仅显示map上的最后一个点,因此我正在尝试使用数组。我已经创建了一个函数,但是当调用wpoint数组时,我在运行时收到错误“fatalerror:无法索引空缓冲区”。代码如下:funcinitializeRoute(){sharedInstance.database!.op

iOS swift : How to store the index of all duplicate values in array?

让我们以我有这个数组为例:letdates=["01/02/16","02/02/16","03/02/16","01/02/16","02/02/16"]我喜欢做的是将每个String日期作为键存储在字典中,对于每个重复的键,我喜欢将其索引存储为数组,并将其与重复键。例如,01/02/16出现在索引0和3处。02/02/16出现在索引1和4处。我喜欢这样的字典:["01/02/16":[0,3],"02/02/16":[2,4],"03/02/16":[1]]我知道如何跟踪有多少重复条目是这样的:letdates=["01/02/16","01/02/16","02/02/16","

ios - NSLocale.current.language 返回错误值

这个问题在这里已经有了答案:NSLocalereturningwrongvalueiniOS11(1个回答)关闭4年前。当我在iPhone设置中更改我的语言时,它不会反射(reflect)在NSLocale.current.language中。这是因为我的应用不支持西类牙语吗?我希望它无论如何都能得到反射(reflect)。最终,我试图获取用户首选语言的ISO639-1(2位)区域代码。代码:guardvarpreferredLanguage=NSLocale.preferredLanguages.firstelse{return}forlanguageinNSLocale.prefe

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