草庐IT

non-compliant

全部标签

ios - swift - "unexpected non-void return value in void function"

我已经开始编写一个用户类,它有一个方法来计算用户与对象的距离。它看起来像这样:classUser{varsearchRadius=Int()varfavorites:[String]=[]varphoto=String()varcurrentLocation=CLLocation()funccalculateDistance(location:CLLocation){letdistance=self.currentLocation.distanceFromLocation(location)*0.000621371returndistance//Errorreturnsonthisli

swift 2 : Try/Catch a non-throwing function

我正在重构一个Obj-c类,其中在removeObserver:周围有一个@try/@catchblock。在swift中做同样的事情会触发警告,因为removeObserver可能会失败(当没有观察者时)但它不会抛出任何错误。知道如何实现相同的行为吗?编辑:我的代码:try{self.removeObserver(self,forKeyPath:"LineDisplayChanged")} 最佳答案 您调用的funcremoveObserver(_anObserver:NSObject,forKeyPathkeyPath:Stri

swift - FetchedResultsController Swift 3 API 滥用 : Attempt to serialize store access on non-owning coordinator

我正在尝试使用fetchedResultsController来处理我的UITable中的结果。它最初在程序启动时工作。然后,当我切换回我的表所在的库存选项卡时(再次为viewToAppear),这就是它崩溃的时候。我在包含表格的窗口的viewWillAppear()方法中遇到运行时崩溃错误。特别是它在Inventory+CoredataProperties.swift文件这一行letcharacters=name!.characters.map{String($0)}上崩溃,但我怀疑错误出在其他地方这最初有效,为什么现在不在第二次重新加载?这是函数。overridefuncviewW

final var 和 non-final var 之间的快速区别 |最终让和非最终让

final变量和非final变量的区别:varsomeVar=5finalvarsomeFinalVar=5和letsomeLet=5finalletsomeFinalLet=5 最佳答案 final修饰符在SwiftLanguageReference中描述。,它说finalApplythismodifiertoaclassortoaproperty,method,orsubscriptmemberofaclass.It’sappliedtoaclasstoindicatethattheclasscan’tbesubclassed.

ios - swift 4 "This class is not key value coding compliant"

我有一个Swift库,它严重依赖obj.valueForKey()中的NSObject。迁移到Swift4后,我发现这些调用总是崩溃并出现错误“此类不是键的键值编码兼容的...”,除非我正在寻找的属性是用@objc声明的。现在是否必须使用@objc声明属性才能使用此方法找到它们?有替代方案吗? 最佳答案 当您执行迁移时,Xcode询问了@objc推断,您可能选择了新类型而不是Swift3。可能的解决方案:使用@objc根据需要在每个方法上使用@objc而不是整个类。使用@objcMembers你可以在类上使用@objcMembers

swift - "Cannot inherit from non-open class" swift

从Xcode8beta6开始,我现在在其定义模块之外收到编译错误“无法从非开放类(Class)继承”我继承的类是单独的Swift框架的一部分,但我的项目是为Xcode8beta5编译的。我需要更改什么才能让我的项目再次编译? 最佳答案 我自己找到了答案。在Swift3中,您现在可以将类标记为open而不是public这允许模块外部的文件子类化该类。只需将模块类中的public替换为open。引用here. 关于swift-"Cannotinheritfromnon-openclass"s

swift - Swift 中的 'non-nominal type' 是什么?

我在尝试扩展诸如(Int,Int)或Any之类的非正统“类型”时看到此错误:Non-nominaltype'Any'cannotbeextended那么什么使类型成为非标称类型呢?像Any或(Int)这样的非标称类型和像Int这样的常规标称类型有什么区别? 最佳答案 currentlyacceptedanswer不正确;实际答案来自Swift类型系统的一个深奥的部分。Swift中的大多数类型都是标称类型——它们是作为用户代码的一部分在特定模块中声明的“命名”类型。Int和Array等看似原始的类型实际上是Swift模块中定义的结构,

Swift 协议(protocol)错误 : 'weak' cannot be applied to non-class type

Protocols和class-boundProtocols有什么区别,我们应该在Swift中使用哪一个?protocolA:class{...}protocolA{...}当协议(protocol)未定义为:class时尝试添加weak委托(delegate)时出现错误:protocolA{...}weakvardelegate:A给出错误:'weak'cannotbeappliedtonon-classtype或'weak'mustnotbeappliedtonon-class-bound'A';consideraddingaprotocolconformancethathasac

types - 为什么 Swift 语言指南建议使用 Int "even when values are known to be non-negative"?

这是一个关于Swift编程风格的问题,特别是Int与UInt。Swift编程语言指南建议程序员使用通用的有符号整数类型Int,即使已知变量是非负数。来自theguide:UseUIntonlywhenyouspecificallyneedanunsignedintegertypewiththesamesizeastheplatform’snativewordsize.Ifthisisnotthecase,Intispreferred,evenwhenthevaluestobestoredareknowntobenon-negative.AconsistentuseofIntforint

ios - 未捕获的异常 : This class is not key value coding-compliant

这个问题在这里已经有了答案:Xcode-Howtofix'NSUnknownKeyException',reason:…thisclassisnotkeyvaluecoding-compliantforthekeyX"error?(78个答案)关闭7年前。我正在关注atutorialtitled"SwiftTutorialforiOS:NSFileManagerPersistingData",我在29分钟左右或之后遇到了错误。当我尝试在iOS模拟器上运行它时,我收到错误:Terminatingappduetouncaughtexception'NSUnknownKeyException