Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 views
in Technique[技术] by (71.8m points)

compiler errors - Xcode 8.1 swift 3 take forever to compile this code

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
        ]
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...