草庐IT

hardcoded_Value

全部标签

ios - fatal error : unexpectedly found nil while unwrapping an Optional value (lldb)

overridefuncprepareForSegue(segue:UIStoryboardSegue,sender:AnyObject!){ifsegue.identifier=="showLocalMenuDetail"{ifletindexPath=self.tableView.indexPathForSelectedRow(){self.slideMenuController()?.closeLeft()letdestinationController=segue.destinationViewControllerasDetailViewControllerdestinatio

arrays - 选择要附加到三元运算符 'if' 运算符 : "Immutable value... only has mutating members" 的数组

我有两个数组:varaddedToIgnoreList:[String]=[]varremovedFromIgnoreList:[String]=[]我想将一个值附加到这些数组之一。如果我这样做:(isUserIgnored?removedFromIgnoreList:addedToIgnoreList).append("username")我得到Immutablevalueoftype'[String]'onlyhasmutatingmembersnamed'append'如果我使用中间变量,它会起作用:varwhich=isUserIgnored?removedFromIgnore

ios - 准备 segue : Cannot convert value of type 'UIViewController' to specified type 'SecondViewController'

我知道我肯定在这里遗漏了一些明显的东西,但我似乎无法通过它的实际类型来引用目标ViewController。我按照以下步骤从头开始创建了一个新项目来对此进行测试:创建一个新的单View应用程序项目添加一个新的ViewController创建一个新类,子类化UIViewController,并将其命名为SecondViewController将这个新类设置为第二个ViewController的自定义类(现在它的标题是第二个ViewController)向第一个ViewController添加一个按钮,然后按住Ctrl键单击它到第二个ViewController,然后从ActionSegu

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一起出现。[

ios - swift 3.1 : Cannot convert value of type '(_) -> ()' error/Problems with closures

我升级到Swift3.1,我收到了一些新错误,这些错误似乎是3.1语法问题,因为在迁移之前它们不是问题。它们大多与闭包有关,如本例所示:letalert=UIAlertController(title:"Success",message:"Thanksforparticipatinginourraffle!",preferredStyle:UIAlertControllerStyle.alert)alert.addAction(UIAlertAction(title:"OK",style:.default,handler:{performSegue(withIdentifier:"to

objective-c - fatal error : unexpectedly found nil while unwrapping an Optional value, 快速获取 json 错误

获取json错误当我尝试返回json时,出现错误fatalerror:unwrappedlyfoundnilwhileunwrappinganOptionalvalue:funcgetJson(str:NSString)->AnyObject{varproxiesURL=NSURL(string:str)varproxiesDataJson=NSData.dataWithContentsOfURL(proxiesURL,options:NSDataReadingOptions.DataReadingUncached,error:nil)varjson:AnyObject!if(prox

ios - swift/Objective-C : How to get value from object by string name

classA{varx=1}vara=A()如何使用字符串名称(a["x"])从对象“a”获取变量“x”? 最佳答案 如果类继承自NSObject,这将起作用,您可以在其中使用valueForKey:获取属性。importFoundationclassA:NSObject{varx=1}leta=A()letaval=a.valueForKey("x")println("\(aval)")请注意aval在这里是一个AnyObject?因为没有类型信息。您需要自己转换或测试它是什么。 关于

ios - CLLocationManager fatal error : unexpectedly found nil while unwrapping an Optional value Swift

我有一个问题,因为当我尝试获取位置用户并在我的.plist中获得权限时,我的应用程序崩溃了,这是我的代码。importUIKitimportMapKitimportCoreLocationclassmapClass:UIViewController,MKMapViewDelegate,CLLocationManagerDelegate{varlocation4=CLLocation()varlm=CLLocationManager()@IBOutletvarpropMapa:MKMapView!lm.delegate=selflm.desiredAccuracy=kCLLocation

swift - 索引(: Int) method of Range in swift return incorrect value

在半开放范围对象上使用index(of:Int)方法时,如果范围不是从0开始,它总是返回不正确的值。请参见下面的代码。letrange=(3..我不明白为什么会产生这样的结果。谁能解释一下? 最佳答案 索引是不透明的对象。如果它不是数组,则不应假定它们是从零开始的,甚至不应假定它们是整数(有关示例,请参见String.Index)。要获取从零开始的整数索引,您需要获取与startIndex的距离:letrange=(3..但是,对于Int范围,它基本上与以下内容相同:letintegerIndex=5-range.lowerOffs

ios - Swift 通用变量 fatal error : unexpectedly found nil while unwrapping an Optional value

我正在尝试实现一个简单的通用方法:funcfindMax(numbers_array:[T])->(min_tuple:T,max_tuple:T){varmax_number:T?varmin_number:T?foriinnumbers_array{if(max_numberi){min_number=i}}return(min_number!,max_number!)}我正在尝试访问这样的方法:letresult=findMax([3.4,5,-7,-7.8])但是每当我运行这段代码时,我都会收到以下错误:fatalerror:unexpectedlyfoundnilwhileu