最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

[已解决]swift的app在Xcode中编译出错:unknown 0 error a declaration cannot be both final and dynamic

iOS crifan 547浏览 0评论

相关代码:

extension NSDate {
    static let SecondsPerMinute:Int = 60
    static let MinutesPerHour:Int = 60
    static let HoursPerDay:Int = 24
    static let MinutesPerDay:Int = MinutesPerHour * HoursPerDay
    static let SecondsPerHour:Int = SecondsPerMinute * MinutesPerHour
    static let SecondsPerDay:Int = SecondsPerHour * HoursPerDay

编译出错:

CompileSwift normal i386 /Users/crifan/dev/dev_root/daryun/Projects/Qoros/QorosSales/Sourcecode/SalesAppiOS/SalesApp/CrifanNSDate.swift
    cd /Users/crifan/dev/dev_root/daryun/Projects/Qoros/QorosSales/Sourcecode/SalesAppiOS
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/crifan/dev/dev_root/daryun/Projects/Qoros/QorosSales/Sourcecode/SalesAppiOS/SalesApp/CrifanUITextView.swift /Users/crifan/dev/dev_root/daryun/Projects/Qoros/QorosSales/Sourcecode/SalesAppiOS/SalesApp/CrifanLibHttp.swift
。。。
iphonesimulator/SalesApp.build/Objects-normal/i386/CrifanNSDate.d -emit-reference-dependencies-path /Users/crifan/Library/Developer/Xcode/DerivedData/SalesApp-fxzzwvtqreanqsgzqmztnatyyjjd/Build/Intermediates/SalesApp.build/Debug-iphonesimulator/SalesApp.build/Objects-normal/i386/CrifanNSDate.swiftdeps -o /Users/crifan/Library/Developer/Xcode/DerivedData/SalesApp-fxzzwvtqreanqsgzqmztnatyyjjd/Build/Intermediates/SalesApp.build/Debug-iphonesimulator/SalesApp.build/Objects-normal/i386/CrifanNSDate.o
<unknown>:0: error: a declaration cannot be both ‘final’ and ‘dynamic’

去改为:

extension NSDate {
    static let SecondsPerMinute:Int = 60
    static let MinutesPerHour:Int = 60
    static let HoursPerDay:Int = 24
//    static let MinutesPerDay:Int = MinutesPerHour * HoursPerDay
    static let MinutesPerDay:Int = 60 * 24
//    static let SecondsPerHour:Int = SecondsPerMinute * MinutesPerHour
//    static let SecondsPerDay:Int = SecondsPerHour * HoursPerDay
    static let SecondsPerHour:Int = 60 * 60
    static let SecondsPerDay:Int = (60 * 60) * 24

问题依旧。

<unknown>:0: error: a declaration cannot be both ‘final’ and ‘dynamic’

问题在于:

不知道到底是哪段代码出错了。。。

Xcode没有错误提示

A declaration cannot be both ‘final’ and ‘dynamic’ error in Swift 1.2 – Stack Overflow

发现:

其实就是之前解决的问题:

[总结]

纯swift的话,

要把

类中的static let xxx

加上@nonobjc

前缀:

extension NSDate {
    @nonobjc static let SecondsPerMinute:Int = 60
    @nonobjc static let MinutesPerHour:Int = 60
    @nonobjc static let HoursPerDay:Int = 24
    @nonobjc static let MinutesPerDay:Int = MinutesPerHour * HoursPerDay
    @nonobjc static let SecondsPerHour:Int = SecondsPerMinute * MinutesPerHour
    @nonobjc static let SecondsPerDay:Int = SecondsPerHour * HoursPerDay

才可以。

转载请注明:在路上 » [已解决]swift的app在Xcode中编译出错:unknown 0 error a declaration cannot be both final and dynamic

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
61 queries in 0.148 seconds, using 18.09MB memory