草庐IT

ios - 将成员初始化为类函数导致 'self' used in method call错误

我有一个指向其中一个类函数的类属性。但是,当我尝试使用其中一个函数初始化此变量时,出现以下错误:'self'usedinmethodcallbeforeallstoredpropertiesareinitialized.我能够为这些函数初始化任何其他变量,但错误使它听起来像我正在调用函数,即使我不是。importUIKitimportAudioToolboxclassBeatMaker{//iPhone7andupusebeatfunction,iPhone6susebeatFallbacklethapticFunction:()->()letimpactGenerator=UIImp

swift 3 警告 : Non-optional expression of type 'String' used in a check for optionals

我正在将一个项目更新到Swift3,并遇到了以下我似乎无法解决的警告。fileprivatevarfilteredTitlesList:[String]=[]ifletfilteredTitle:String=filteredTitlesList[indexPath.row]asString{//'Non-optionalexpressionoftype'String'usedinacheckforoptionals'//Dosomething}此处类似问题的答案对我没有帮助:Non-optionalexpressionoftype'AnyObject'usedinacheckforo

swift - 为什么会出现 "Static member ' .. .' cannot be used on instance of type ' .. .'"错误?

这是在实例方法中直接使用静态成员的方法:publicstructRankSet{privateletrankSet:UInt8staticletcounts:[UInt8]=[0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,...//Moreofthesame4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8]publicvarcount:Int{get{//TheerrorisonthefollowinglinereturnInt(counts[Int(rankSet)])}}}Swift产生以下错误:Staticmember'counts'cannotb

xcode - ld : -bundle and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together

我想构建我的应用并启用Bitcode。据我所知,我所有的第3方库依赖项都启用了Bitcode。但是当我进行构建时,出现此错误:ld:-bundle和-bitcode_bundle(Xcode设置ENABLE_BITCODE=YES)不能一起使用我该如何解决这个问题? 最佳答案 我错误地将我的DEBUG和TEST配置设置为使用Bitcode构建,这就是导致上述错误的原因。仅为RELEASE启用Bitcode修复了它:(您的应用程序和任何嵌入式框架目标应如下所示——根本不要在您的测试和UI测试目标上启用Bitcode。)

generics - 为什么这个协议(protocol)可以 "only be used as a generic constraint"?

我正在尝试在Swift中执行以下操作:protocolProtocolWithAlias{typealiasT}protocolAnotherProtocol{funcsomeFunc()->ProtocolWithAlias}但我收到错误:Protocol'ProtocolWithAlias'canonlybeusedasagenericconstraintbecauseithasSelforassociatedtyperequirements。有没有可能做这样的事情?错误消息(或者至少是“onlybeusedasagenericconstraint”部分)对我来说似乎没有多大意义。

ios - Xcode UIView.init(帧 :) must be used from main thread only

我正在尝试在后台线程中渲染一些View以不影响主线程。在Xcode9之前,这从来都不是问题。DispatchQueue.global(qos:.background).async{letcustomView=UIView(frame:.zero)DispatchQueue.main.async{self.view.addSubview(customView)}}UIView.init(frame:)mustbeusedfrommainthreadonly这个错误出现在第二行。更新AppleUIView文档实际上在线程注意事项部分中说:Manipulationstoyourapplica

ios - 为什么在 Swift 中初始化变量的那一行会出现 "Variable used before being initialized"错误?

我很难理解为什么在使用Swift的iOS项目中会出现此编译器错误。如果我创建以下类:classInitTest{leta:Intletb:Intletc:Intinit(){self.a=3self.b=4self.c=self.runCalculation()}funcrunCalculation()->Int{returnself.a*self.b}}我在self.c=self.runCalculation()行上收到一个编译器错误,提示“在初始化之前使用了变量‘self.c’”。起初我以为这是因为编译器无法验证runCalculation()方法没有访问self.c,但后来我尝试

ios - swift 错误 : Variable used within its own initial value

当我初始化一个实体的实例时,出现错误Variableusedwithinitsowninitialvalue。这是抛出错误的代码:classfuncbuildWordDefinition(word:String,language:Language,root:TBXMLElement)->WordDefinition{letword=WordDefinition(word:word,language:language)错误指向word变量。这是WordDefinition类:classWordDefinition{letword:Stringletlanguage:Languageini

swift - "Protocol ... can only be used as a generic constraint because it has Self or associated type requirements"是什么意思?

我正在尝试创建一个以Swift中的自定义协议(protocol)为键的字典(实际上是一个HashSet),但它在标题中给出了错误:Protocol'myProtocol'canonlybeusedasagenericconstraintbecauseithasSelforassociatedtyperequirements而且我无法理解它的正反面。protocolObserving:Hashable{}varobservers=HashSet() 最佳答案 协议(protocol)Observing继承自协议(protocol)Ha

c# - 如何防止 EF "The context cannot be used while the model is being created"错误?

查看我的Elmah错误日志,我看到一些来自EntityFramework的InvalidOperationException处理:Thecontextcannotbeusedwhilethemodelisbeingcreated.这是来自Nuget的最新EFCodeFirst库。我能够在网上找到的唯一信息是它是由将数据上下文作为单例引起的,这肯定不是我的情况。在我的Windsor安装程序中,我的EF工作单元结构正在注册:container.Register(Component.For().ImplementedBy().LifeStyle.PerWebRequest);我能够通过在VS