草庐IT

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

Swift:返回一个 In-Out 函数

如何编写一个函数,该函数返回另一个采用输入输出参数的函数?我想编写返回incrementor函数的函数makeIncrementor。此incrementor函数采用一个In-Out参数并将其递增一定量(它不返回任何内容)。这是我的代码:funcmakeIncrementor(amount:Int)->Int->Void{funcincrementor(inoutvariable:Int)->Void{variable+=amount;}returnincrementor;}varx=1;varinc=makeIncrementor(2);inc(&x)//xshouldnowcont

ios - 错误 "NSMutableRLEArray objectAtIndex:effectiveRange::Out of bounds'“

我有以下代码,其中我传递了一个"Hello|rWorld|g"类型的字符串,下面的函数将它转换为attributedString"Hello"为红色,"World"为绿色。我在传递数组中的每个字符串时使用了它。该函数只为文本着色,直到它找到最后期间条件中显示的特殊字符,然后为文本着色。代码:funcformatAttributedString(string:String)->NSMutableAttributedString{varstrCopy=stringasNSStringvarcolor:UIColor=UIColor()varattributedString:NSMutabl

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()

ios - SWIFT 幻灯片一对象 "in and out"

有没有办法在swift中为一个对象(UIView、UIButton等)设置动画,使其在屏幕左侧滑出并同时在屏幕右侧滑入,即f.e.的部分已经从左侧滑出的UIView已经从右侧再次滑入。我希望你能理解我的问题,解释这个问题有点棘手。我正在使用Xcode+Swift3.0。谢谢。 最佳答案 thatthepartsoff.e.anUIViewthatalreadyslidedoutontheleftsidearealreadyslidinginagainfromtherightside这差点被我漏掉了。让一个“View”出现在屏幕上的两

ios - Firebase iOS 用户认证 : avoiding getting logged out of app

在我的整个应用程序中,我使用两种方式在任何给定时间获取当前用户ID。他们两个我都在某个地方捡到并且(据我所知)工作得很好。然后我使用方法3作为方法2的变体。方法一:ifletuser=Auth.auth().currentUser{letuid=user.uid}方法二:handle=Auth.auth().addStateDidChangeListener{(auth,user)inifletuser=user{//Userissignedin.self.USER=userself.userID=self.USER?.uid}else{//Nouserissignedin.letvc

ios - 错误 : "array index out of range" in multidimensional array

我已经声明了我的数组vartile=[[Int]]()然后我像初始化它的值一样for(varindex=0;index运行时报错“数组索引超出范围” 最佳答案 正如评论员@C_X和@MartinR所说,您的数组是空的。以下是如何根据需要对其进行初始化...vartile=[[Int]](count:4,repeatedValue:[Int](count:4,repeatedValue:0))forindexin0.....当然,for循环现在是多余的,如果您只想要零! 关于ios-错误:

arrays - Swift - 追加对象 : array index out of range

当我尝试将一个项目添加到我的数组时,它给我和EXCBADInstruction错误,它说fatalerror:Arrayindexoutofrange这是代码:vartabelle:[[Actions]]=[[]]funcdoSomething(){varresults=self.fetch()varoldProjektName:String=results[0].projektNamevarcount:Int=0foriteminresults{ifoldProjektName==item.projektName{tabelle[count].append(item)}else{co

java - 获取 java.net.SocketTimeoutException : Connection timed out in android

我对android开发比较陌生。我正在开发一个android应用程序,我在其中向Web服务器发送请求并解析JSON对象。在与服务器通信时,我经常收到java.net.SocketTimeoutException:Connectiontimedout异常。有时它会完美地工作而没有任何问题。我知道同样的问题已经被问过很多次了。但是,对于这个问题,我仍然没有得到任何令人满意的解决方案。我在下面发布了我的logcat和应用服务器通信代码。publicJSONObjectRequestWithHttpUrlConn(String_url,Stringparam){HttpURLConnectio