Xcode 8.1 swift 3永远需要编译此代码 [英] Xcode 8.1 swift 3 take forever to compile this code

查看:82
本文介绍了Xcode 8.1 swift 3永远需要编译此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以前使用swift 2.3的项目中有此类。当我将项目迁移到Swift 3时,xcode花费了很多时间进行编译,而我发现它停留在此类中。由于此类,我无法构建整个项目。有没有一种方法可以修改此类,以便可以构建项目,因此Xcode花费了很多时间来编译这段代码。如果我从MyClass中删除了几个属性,Xcode将迅速重新编译。有人对如何解决这个问题有任何想法吗?

I have this class in a project which previously use swift 2.3. When i migrated the project to swift 3, xcode took forever to compile and i saw it stuck at this class. I can not build the whole project because of this class. Is there a way to modify this class so the project can be built, it took Xcode forever to compile this piece of code. If i removed several properties from MyClass, Xcode will quickly compile again. Anyone has any idea on how to solve this problem?

import Foundation

class MyClass: NSObject {

    var id: String = ""
    var uid: String = ""
    var uname: String = ""
    var fname: String = ""
    var txt: String = ""
    var hay: Float = 0
    var flag = false
    var long: Double = 0
    var lat: Double = 0
    var altitude: Double = 0
    var course: Double = 0
    var speed: Double = 0
    var lname: String = ""
    var city: String = ""
    var country: String = ""
    var sublocal: String = ""
    var subarea: String = ""
    var thumb: String = ""
    var trash = false
    var date: Double = 0
    var updated: Double = 0
    var furl: String = ""

    func toAnyObject() -> Any {
        return [
            "id": id,
            "uid": uid,
            "uname": uname,
            "fname": fname,
            "txt": txt,
            "hay": hay,
            "flag": flag,
            "long": long,
            "lat": lat,
            "altitude": altitude,
            "course": course,
            "speed": speed,
            "lname": lname,
            "city": city,
            "country": country,
            "sublocal": sublocal,
            "trash": trash,
            "subarea": subarea,
            "thumb": thumb,
            "date": date,
            "updated": updated,
            "furl": furl
        ]
    }
}


推荐答案

不用大字典文字即可重写。因此:

Rewrite without the big dictionary literal. So:

func toAnyObject() -> Any {
    var d = [String:Any]()
    d["id"] = id
    d["uid"] = uid
    // ... and so on ...
    return d
}

这篇关于Xcode 8.1 swift 3永远需要编译此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆