草庐IT

vec_bool

全部标签

swift - 'fileExists' 产生 'Bool' ,而不是预期的上下文结果类型 'Bool'

这行代码:if!FileManager.fileExists(atPath:documentDirectory.appendingPathComponent("newname.pdf"))出现错误提示'fileExists'produces'Bool',nottheexpectedcontextualresulttype'Bool'在Xcode9.2上。我错过了什么? 最佳答案 您需要在FileManager的实例上调用fileExists。它不是类方法。FileManager提供在大多数情况下使用的默认实例。if!FileMana

objective-c - Throwing 方法不能是@objc 协议(protocol)的成员,因为它返回类型为 'Bool' 的值

我收到以下错误:Throwingmethodcannotbeamemberofan@objcprotocolbecauseitreturnsavalueoftype'Bool';return'Void'oratypethatbridgestoanObjective-Cclass定义Swift协议(protocol)时也需要桥接到Objective-C:@objcpublicprotocolSaving{funcsave()throws->Bool}是否有其他方法可以定义返回Bool的Swift方法,可能会抛出错误并与Objetive-C兼容? 最佳答案

linux - Swift Linux 生成随机 bool

我正在尝试对Bool进行静态扩展,以便在调用时返回随机的true/false值。我正在努力使这项工作:staticfunccoinFlip()->Bool{#ifos(Linux)srand(UInt32(time(nil)))letresult=Int(random()%2)ifresult==0{returnfalse}else{returntrue}#elsereturnarc4random_uniform(2)==0#endif}我在服务器端Swift应用程序中调用的路由范围内使用它。每当它第一次被调用时,它都会返回一个随机值,但在同一范围内对该函数的所有后续调用都不会随机化输

ios - 无法将 ComparisonResult 转换为闭包结果类型 Bool

这是我的代码:vardata=[list]()varfiltered=[list]()structlist{varlabel1:String=""varlabel2:String=""varlabel3:String=""}funcsearchBar(_searchBar:UISearchBar,textDidChangesearchText:String){filtered=data.filter{$0.label1.localizedCaseInsensitiveCompare(searchText)}if(filtered.count==0){searchActive=false

swift - setNavigationBarHidden(Bool, Bool) 动画的默认时间间隔

Swift动画的默认时间间隔是多少,例如的setNavigationBarHidden(Bool,animated:Bool)和setToolbarHidden(Bool,animated:Bool)方法>UINavigationController类?我想知道我的动画是否匹配相同的持续时间。 最佳答案 来自Appledocs:UINavigationControllerHideShowBarDurationAglobalconstantthatspecifiesapreferreddurationwhenanimatingthen

swift - 与 nil 比较并在 Swift 中返回一个 bool

更新:这个问题在Xcodebeta5之后不再是问题似乎beta3版本重构了“nil”在引擎盖下的工作方式,但没有提供足够的文档。我的这段代码在beta2中运行良好:funchasLogin()->Bool{returnself.credentail!=nil}但在beta3中,我得到了这个错误Type'NativeObject'doesnotconformtoprotocol'NilLiteralConvertible'self.credential是'Credential'协议(protocol)的可选值,由NSObject子类实现@objcprotocolCredential:NS

swift - 更改用户默认 bool Swift 的默认值

我有代码:letuserDefaults=NSUserDefaults.standardUserDefaults()ifletbranchcheck=userDefaults.boolForKey("someBooleanValue")asBool?{println("foundbooleanas\(branchcheck)")}这很棒,只有当没有向用户默认值添加任何内容时,它才会自动返回“false”。我希望所有设置都默认为“真”。这是如何实现的? 最佳答案 根据NSUserDefaults/AccessingPreference

ios - 快速 bool 值

这真是令人费解。有人有什么想法吗?letviewHasMovedToRight==false//initiallyIwantthistobefalse然后funcmoveViewToRight(sender:UIButton!){ifviewHasMovedToRight==false{viewHasMovedToRight==true;UIView.animateWithDuration(0.75,animations:{},completion:{(value:Bool)inprintln("moved")})}else{viewHasMovedToRight==false;UIV

swift : Cannot invoke 'filter' with an argument list of type '(@noescape (Int) throws -> Bool)'

我遇到了这个错误:funccompactCoords(coords:[Int])->[Int]{returncoords.filter({(value)->Boolinreturnvalue!=0})}无法使用类型为“(@noescape(Int)throws->Bool)”的参数列表调用“filter”感谢您的帮助! 最佳答案 您的代码在Xcode7.1中运行良好。您可能不小心尝试在Xcode6.x中运行此代码?你可以像这样缩短你的函数:funccompactCoords(coords:[Int])->[Int]{returnco

ios - 来自 UI 控件的奇怪 Bool 类型

我有一个(String,Bool)元组数组:varnames:[(name:String,important:Bool)]=[("Paul",true),("Peter",false)]我还有一个UISwitch控件:@IBOutletweakvarimportantSwitch:UISwitch!我想添加到数组中,使用开关状态来确定Bool。以下不有效:names.append(name:"whatever",important:importantSwitch.on)XCode报告的问题是“类型T不符合协议(protocol)IntegerLiteralConvertible”。这些