草庐IT

optional_argument

全部标签

swift - Swift 或其他语言中 Optionals 的术语

在Swift中,我们操作的元素都有类型。当我们使用这些类型时,我们可以添加“!”、“?”或无来表达它们的可空性。我应该怎么称呼“?”或“!”来表达这种特质?类型装饰器?装饰师?运算符(operator)?还有别的吗?我应该如何称呼使用这个字符时创建的类型?它是一种新类型吗?它是装饰型的吗?类型变体?swift编译器似乎将它们视为新类型,但是我的问题与实现或语言无关,因此我将其标记为与语言无关。编辑:我正在寻找一个与语言无关的名称。我了解到pranjalsatija的注释选项被定义为复合类型。但是,这是一个语言实现细节。我可以将我的问题改写为:类型定义中有特殊含义的字符怎么称呼,派生类型

swift - 错误 : unable to spawn process (Argument list too long) in Xcode Build

我收到这个错误:"error:unabletospawnprocess(Argumentlisttoolong)**ARCHIVEFAILED**Thefollowingbuildcommandsfailed:CompileSwiftSourcesnormalarm64com.apple.xcode.tools.swift.compiler(1failure)Exitcode=65"我浏览了这个链接:Xcodeexportlocalizationthrowserror"Argumentlisttoolong"这篇文章提供了一个很好的临时解决方案来解决减少路径层次的问题。但这似乎不是一个

ios - Swift UITableViewCell detailTextLabel.text 抛出错误 'fatal error: Can' t unwrap Optional.None'

这是生成表格View的Swift代码。我正在尝试设置带有详细信息标签的tableView。我相信问题的产生是因为if(cell==nil){println("1")cell=UITableViewCell(style:.Subtitle,reuseIdentifier:"CellSubtitle")//cell=tableViewCell}永远不会被调用,因此单元格永远不会使用UITableViewCellStyle.Subtitle样式进行初始化。以下是该方法所需的代码:functableView(tableView:UITableView!,cellForRowAtIndexPat

ios - Swift Optionals - 不一致?

我有点困惑——我以为我了解Optionals并且在Apple开发论坛ChrisL上提到了解决不可变Optional问题的一个方法是为可选值类型创建一个类包装器。-link!但是以UIWindow(具有各种属性的可选类类型)为例使用可选链,属性似乎仍然不可变!varwindow:UIWindow?//thisworks(forceunwrap)self.window!.backgroundColor=UIColor.greenColor()//thisoptionalchaindoesn'twork...whynot?Isn'tthisjustasaferversionoftheabov

json - iOS swift :"JSON text did not start with array or object and option to allow fragments not set."

当我在swift中将Json字符串转换为字典时,我遇到了问题:ErrorDomain=NSCocoaErrorDomainCode=3840“JSON文本不是以数组或对象开头,并且允许未设置片段的选项。”UserInfo={NSDebugDescription=JSON文本未以数组或对象开头,并且未设置允许片段的选项。}我不知道如何解决这个问题,请给出解决问题的想法。这里我给出了我尝试过的代码..Json字符串转字典的方法是,funcconvertToDictionary(fromtext:String)throws->[String:String]{guardletdata=text

Swift 泛型错误 : Cannot convert value of type 'Type<T>' to expected argument type 'Type<_>'

请考虑以下设置:protocolMyProcotol{}classMyModel:MyProcotol{}enumResult{casesuccess(value:T)casefailure}classTest{functest(completion:(Result)->Void){letmodel=MyModel()letresult=Result.success(value:model)completion(result)}}为什么我不能调用completion(result)?我收到此错误:无法将“Result”类型的值转换为预期的参数类型“Result”任何解决方法?

ios - fatal error : unexpectedly found nil while unwrapping an Optional value in UITableViewCell

问了类似的问题here但这并不能为我解决这个问题。我添加了tableView在ViewController.使用它的数据源和委托(delegate)扩展类并为其添加所需的方法。然后我在此表中创建了一个原型(prototype)单元格(不是单独的.xib)并为此创建了一个类TableViewCell并收集了@IBOutlet:@IBOutletweakvartitleOfAccount:UILabel!@IBOutletweakvarlastModified:UILabel!@IBOutletweakvaraccountImage:UIImageView!@IBOutletweakvar

swift - SKNode 子类生成错误 : cannot invoke initializer for type "X" with no arguments

SKNodes可以用一个空的初始化器来初始化,例如,letnode=SKNode()。但是,子类化SKNode会破坏此功能。在子类化SKNode之后,Xcode在尝试在子类上使用空初始化程序时生成此错误:Cannotinvokeinitializerfortype"X"withnoarguments假设SKNodeSubclass是SKNode的子类,行letnode=SKNodeSubclass()会生成此错误。IsitpossibletosubclassfromSKNodeandalsouseanemptyinitializerlikewithSKNode?classStatusS

ios - Swift 编译器错误 : Cannot invoke 'lockForConfiguration' with an argument list of type '(() -> ())'

这是Swift2。我似乎找不到任何相关信息。我收到错误Cannotinvoke'lockForConfiguration'withanargumentlistoftype'(()->())'这里是第二行。ifletdevice=captureDevice{device.lockForConfiguration(){device.videoZoomFactor=1.0+CGFloat(ratioValue)device.unlockForConfiguration()}print(ratioValue)} 最佳答案 在Swift2中,

ios - swift 错误 : Cannot pass immutable value as inout argument: 'pChData' is a 'let' constant

我有一个如下所示的函数:funcreceivedData(pChData:UInt8,andLengthlen:CInt){varreceivedData:Byte=Byte()varreceivedDataLength:CInt=0memcpy(&receivedData,&pChData,Int(len));//GettingtheerrorherereceivedDataLength=lenAudioHandler.sharedInstance.receiverAudio(&receivedData,WithLen:receivedDataLength)}获取错误:Cannotp