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
873 views
in Technique[技术] by (71.8m points)

ios - error after updating the Xcode to 7.0

I'm developing an iOS application in Swift. When I updated the Xcode to 7.0, I'm getting error in swiftyJSON.

 static func fromObject(object: AnyObject) -> JSONValue? {
    switch object {
    case let value as NSString:
        return JSONValue.JSONString(value as String)
    case let value as NSNumber:
        return JSONValue.JSONNumber(value)
    case let value as NSNull:
        return JSONValue.JSONNull
    case let value as NSDictionary:
        var jsonObject: [String:JSONValue] = [:]
        for (k:AnyObject, v:AnyObject) in value {// **THIS LINE- error: "Definition conflicts with previous value"**
            if let k = k as? NSString {
                if let v = JSONValue.fromObject(v) {
                    jsonObject[k] = v
                } else {
                    return nil
                }
            }
        }

What's the problem? Can you help, please?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)
 for (k:AnyObject, v:AnyObject) in value { .. }

must be written in Swift 2 as

for (k, v) : (AnyObject, AnyObject) in value { .. }

From the Xcode 7 release notes:

Type annotations are no longer allowed in patterns and are considered part of the outlying declaration. This means that code previously written as:

var (a : Int, b : Float) = foo()

needs to be written as:

var (a,b) : (Int, Float) = foo()

if an explicit type annotation is needed. The former syntax was ambiguous with tuple element labels.

But in your case the explicit annotation is actually not needed at all:

for (k, v) in value { .. }

because NSDictionary.Generator is already defined as a generator returning (key: AnyObject, value: AnyObject) elements.


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

...