草庐IT

MYLIB_FUNCTION_ATTRIBUTE

全部标签

swift 3 : How to catch error if NSCoder decodeX function decodes wrong value type?

Swift3改变了NSCoder的工作方式。正如其他SO问题所提到的,要解码Int或Bool等值类型,您必须使用特定函数。例如,decodeInteger用于解码Int值,如下所示:letvalue=decodeInteger(forKeykey:TestKey)但是,如果decodeInteger返回的值是String或Bool或Int以外的值怎么办?或者如果TestKey实际上映射为空,因为它包含错误的key数据怎么办?如何优雅地捕获这些错误? 最佳答案 在非整数键上使用decodeInteger会引发异常。遗憾的是,这是一个S

ios - NSLayoutConstraint 没有成员 'Attribute'

我正在尝试转换下面的swift代码NSLayoutConstraint.Attribute.height我正在使用SkeletonView,它在执行时抛出错误。我找不到那个新的替换语法类型“NSLayoutConstraint”没有成员“Attribute” 最佳答案 这完全取决于您使用的Swift版本。NSLayoutConstraint.Attribute.height//Swift4.2NSLayoutAttribute.height//Swift3.0+NSLayoutAttributeHeight//Swift2?

ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : Unknown layout attribute'

我正在尝试以编程方式向UIView中的按钮添加约束:letconstraint=NSLayoutConstraint(item:arrowButton,attribute:NSLayoutAttribute.LeadingMargin,relatedBy:NSLayoutRelation.Equal,toItem:self,attribute:NSLayoutAttribute.NotAnAttribute,multiplier:1,constant:10)arrowButton.addConstraint(constraint)我希望按钮的前边距距离View的左边距为10。此代码在V

ios - swift 2.0 : `print` function generates "Argument passed to call that takes no arguments" error

类中的print函数神秘地生成以下错误:Argumentpassedtocallthattakesnoarguments。但是,如果我们使用Swift.print而不是仅仅使用print来调用函数,错误就会消失。我们使用的是Swift2和Xcode7。为什么会这样?在生成错误的地方测试下面的函数:functest(){print("whydoesthisfail")} 最佳答案 However,theerrorgoesawayifweuseSwift.printinsteadofjustprinttoinvokethefunctio

swift - : in Swift function signatures and why is there no comma when it seems there should be one?是什么意思

这是我所说的示例:https://developer.apple.com/documentation/foundation/nsmutableorderedset/1410287-insert插入函数显示为insert(_:at:)实际使用时,插入函数看起来更像:namesArray.insert("John",at:3)在"John"之后没有:(虽然我想它可能是"John":String--就是它在那里的样子for?),而文档中的函数签名中没有提到实际需要去那里的,。当我实际使用它时,我是否应该知道/假设逗号在那里?所有Swift函数都是这种情况吗?请注意,这不是关于下划线_的问题—

swift - 核心数据 : How do I store a custom object as a transformable attribute?

目前我有一个名为Place的类定义如下:classPlace{letname:Stringletaddress:Stringletcoordinate:CLLocationCoordinate2Dlettype:StringvarphotoReference:String?varphoto:UIImage?/*functionsetc*/}在我的数据模型中,我有一个名为FoundPlaces的实体。它有一个属性place,类型为“transformable”。我快要发疯了,试图找到存储此对象的Swift解决方案。开头的数据模型是不是错了?任何指导表示赞赏。谢谢!

ios - LLVM 错误 : Broken function found, 编译中止

这里是swift中的几行简单代码:letumAB:Unmanaged=ABAddressBookCreate()letab:ABAddressBookRef=umAB.takeRetainedValue()第二行中断了代码编译,这是我得到的错误:Bitcastrequiresbothoperandstobepointerorneither%27=bitcast%objc_object*%26to%PSs9AnyObject_,!dbg!170LLVMERROR:Brokenfunctionfound,compilationaborted!Command/Applications/Xco

swift 泛型 : Custom closure with multiple arguments for filter function

我有一个缓存数组,可以存储不同类型的对象,如UIView、UICollectionReuableView等vararrCache=[AnyObject]()我想通过传递自定义闭包来使用内置过滤器函数过滤掉这些特定元素:privatefuncreusableViewsClosure(element:AnyObject,type:T)->Bool{returnelementisT?true:false}现在,当我在过滤器函数上调用这个闭包时,我得到一个错误说明leti=arrCache.filter(reusableViewsClosure(UIView))//错误:无法将调用结果类型bo

swift - Xcode 10.1 swift 4.2 运算符重载导致编译器警告 : "All paths through this function will call itself"

所以我突然收到这个编译器警告,它在swift3或(我认为)swift4.0上不存在。下面的代码重载+=运算符以执行向量增量:publicfunc+=(left:inoutCGVector,right:CGVector){left+=right}并产生警告,我很困惑任何人都可以阐明为什么会发出警告以及出了什么问题吗? 最佳答案 当您执行left+=right时,它会调用您定义的同一函数。换句话说,您的运算符重载函数+=(左:inoutCGVector,右:CGVector)将始终调用自身(无限递归)。你正在做类似的事情funcfoo(

function - 为什么编译器以不同的方式对待闭包和局部函数?

我认为闭包和函数是一回事。但是当在本地函数编译器中引用属性时不需要self.但是在闭包里面需要写self.我的意思是为什么这两件事不同?为清楚起见,示例代码:classFoo{letbar="bar"funcbaz(){funclocalBaz(){println(bar)//Nocomplainfromcompiler.}letbazClosure={println(self.bar)//HereifIwritejustprintln(bar),compilercomplains.}}} 最佳答案 你的期望是错误的-Swift中的