草庐IT

constructor_arguments

全部标签

swift - 无法调用类型 : with an argument list of type '(_Element)' 的初始值设定项

我是Swift的新手。我正在尝试将字符串转换为字符数组,并且我想要字符的整数值。这是我的代码:varstring="1234"vartemp=Array(string.characters)varo=Int(temp[0])但是在第3行我遇到了上述错误。这段代码有什么问题?请帮助我 最佳答案 您需要将Character映射到String,因为Int没有Character初始值设定项。您还可以将字符数组映射到字符串数组vartemp=string.characters.map(String.init)或在初始化变量时将字符转换为字符串

ios - "Missing argument for parameter ' 样式' in call"创建系统UIBarButtonItem 错误

我不明白为什么编译器要求在这个系统风格的UIBarButtonItem初始值设定项中为样式参数提供参数——它首先没有那个参数。帮助?这是Swift的错误吗?classExpensesViewController:UIViewController{lazyvarnewExpenseBarButtonItem=UIBarButtonItem(barButtonSystemItem:.Add,target:self,action:Selector("newExpenseBarButtonItemTapped:"))funcnewExpenseBarButtonItemTapped(){}}

swift - Rx swift : Extra argument 'onError' in call

我在带有RxSwift的Swift4中有以下代码worthReacting.flatMap{(userSearch)intranslator.getTranslation(ofWord:userSearch)}.subscribe(onSuccess:{(dataModel)instate.value=.translation(word:dataModel.definition,translations:dataModel.translations)},onError:{(error)instate.value=.networkError},onCompleted:{state.val

swift - React Native Swift 组件 : how to set the constructor

我已经在一个ReactNative项目上工作了一个星期,我想制作我自己的Objc/Swift原生组件。我遵循了官方文档,但我发现它没有那么详细。我可以使用回调等,Ialsofollowedthis,但找不到我想要的。我想使用我的类的构造函数init(),但每次我编译时,应用程序启动并且Xcode抛出以下错误:fatalerror:对类“myProject.MyModule”使用了未实现的初始化程序“init()”我尝试了很多方法,例如在init()前面添加@objc,但没有任何效果。我有点迷路了。我的文件(我使用的是Swift3):MyModule.m:#import@interfac

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"这篇文章提供了一个很好的临时解决方案来解决减少路径层次的问题。但这似乎不是一个

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”任何解决方法?

constructor - Swift - 使构造函数参数上的标签可选?

例如,假设您有以下代码:structSomeStruct{init(arg1:String,arg2:Int){//DoesStuffwithVariables}}//SomePointLatervarstr="fasfsad"varinteger=343letsmth=SomeStruct(arg1:str,arg2:integer)是否可以修改SomeStruct结构以使以下代码行合法?letsmth=SomeStruct(str,integer) 最佳答案 是的,您可以通过对外部参数名称使用下划线来使参数匿名:structSo

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