草庐IT

any_cast

全部标签

ios - 比较 Any 类型的两个属性

我正在尝试比较一个类的两个实例的属性。我以前用过它并且工作正常:overridepublicfuncisEqual(_object:Any?)->Bool{ifletrhs=objectas?BankDataModel,self.accountHolderName==rhs.accountHolderName,self.accountNumber==rhs.accountNumber,self.accountHolderThirdPartyAccountOwner==rhs.accountHolderThirdPartyAccountOwner,self.bankName==rhs.b

ios - 崩溃 : Container. swift 行 299 Container.resolve<A, B>(条目 : ServiceEntryProtocol, 调用程序 : (B) -> Any) -> A?

最近我在尝试解析对象时开始崩溃。以下是崩溃日志。我可以在Container.swift的第299行guardletcurrentObjectGraph=currentObjectGraphelse{fatalError()}中看到应用程序没有获取currentObjectGraph,它失败了。可能的原因是什么?在我的项目中,我有一个全局级别的汇编程序,它添加了来自不同框架的所有程序集。但是当我试图解决一个对象时,它会崩溃。这是一个中间问题:-#15.Crashed:com.apple.NSURLSession-work0libswiftCore.dylib0x109a1b95cspec

ios - 错误 : Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePickerController.InfoKey'

这个问题在这里已经有了答案:Cannotsubscriptavalueoftype'[String:Any]'withanindexoftype'UIImagePickerController.InfoKey'(8个答案)关闭3年前。我正在尝试通过CoreML重建用于图像检测的Apple测试应用程序,但出现错误:Cannotsubscriptavalueoftype'[String:Any]'withanindexoftype'UIImagePickerController.InfoKeyextensionImageClassificationViewController:UIImag

swift - 将 Any 转换为数组

这是我尝试使用的代码structA{varx:Int=0}structB{vary:Int=0}varc:[String:Any]=["a":[A()],"b":[B()]]for(key,value)inc{letarr=valueas![Any]}它只是抛出异常。尝试将Any转换为[Any]时引发运行时异常。我想要实现的主要目标是遍历Any的元素,如果Any是数组的话。对我来说,将Any转换为[Any]是很自然的,但由于某种原因,它不起作用。那么我怎样才能swift做到这一点呢?我看到了一些将Any转换为[A]或[B]的变通方法,但我的情况并非如此,因为数组可以只包含任意结构。

swift - SecIdentity + Force Cast 违规 : Force casts should be avoided. (force_cast)

请不要标记重复的问题。大家好,我正在执行NSURLAuthenticationMethodClientCertificate,我在其中使用以下代码。如果我不使用swiftlint,哪个代码没问题。但是当我使用swiftlint时出现这个错误并且无法解决这个问题。尝试了很多请帮助我。在下面发布代码。varitems:CFArray?//letPKCS12Data=DataSourceManager.sharedInstance.serverPolicyManager?.PKCS12DatasecurityError=SecPKCS12Import(certData,options,&it

swift - 为什么我们需要显式地将可选类型转换为 Any?

根据Apple文档,TheAnytyperepresentsvaluesofanytype,includingoptionaltypes.SwiftgivesyouawarningifyouuseanoptionalvaluewhereavalueoftypeAnyisexpected.IfyoureallydoneedtouseanoptionalvalueasanAnyvalue,youcanusetheasoperatortoexplicitlycasttheoptionaltoAny,asshownbelow.varthings=[Any]()things.append(3)/

ios - 覆盖 touchesBegan : Error - method does not override any method from superclass

我正在尝试覆盖UITapGestureRecognizer的自定义子类中的touchesBegan。代码如下。我从这里得到它:Howtoacceleratetheidentificationofasingletapoveradoubletap?.这是公认的答案,但我收到一个错误:方法不会覆盖其父类(superclass)中的任何方法。我已经检查过了,这似乎确实是touchesBegan的签名。帮忙?importUIKitclassUIShortTapGestureRecognizer:UITapGestureRecognizer{lettapMaxDelay:Double=0.3ove

swift - 字符串字典 :Any does not conform to protocol 'Decodable'

这个问题在这里已经有了答案:Fatalerror:DictionarydoesnotconformtoDecodablebecauseAnydoesnotconformtoDecodable(2个答案)关闭4年前。我正在尝试实现一个Decodable来解析json请求,但json请求在对象内部有一个字典。这是我的代码:structmyStruct:Decodable{letcontent:[String:Any]}enumCodingKeys:String,CodingKey{casecontent="content"}但是我收到了这个错误:类型“MyClass.myStruct”不符

swift - [Any] 和 contains() 的数组

我正在尝试测试类型为[Any]的数组包含特定类型的值(例如Int)。我知道Swift不知道如何比较Int和任意类型的值,我想这就是自动完成模板中表达的内容:contains(predicate:(protocol)throws->Bool)所以我尝试了这段代码:letintValue:Int=5//forexampleletisContained=myArrayOfAny.contains({elementinreturn((elementas?Int)==intValue)})...并编译(还不能确定它是否有效);但仍然无法做出predicate:(protocol)的正面或反面部分

ios - 错误 | [iOS] 文件模式 : The `source_files` pattern did not match any file

我将我的现有库重命名为github,我更改了所有内容并且一切正常,除了它现在不验证我的库-podspeclintKJCircularSlider.podspecfortrunkpush。我检查了我的文件夹结构,它看起来很完美,任何人都可以帮助我实际的问题是什么?如果您想检查文件夹结构,这是我的图书馆-KJCircularSlider这是我的podspec文件。Pod::Spec.newdo|s|s.name='KJCircularSlider's.version='0.1.0's.summary='Circularslider-toslidefrom0to100incircularsh