简体   繁体   English

将 Xcode 更新到 7.0 后出错

[英]error after updating the Xcode to 7.0

I'm developing an iOS application in Swift.我正在用 Swift 开发一个 iOS 应用程序。 When I updated the Xcode to 7.0, I'm getting error in swiftyJSON.当我将 Xcode 更新到 7.0 时,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?你能帮忙吗?

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

must be written in Swift 2 as必须用 Swift 2 编写为

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

From the Xcode 7 release notes:来自 Xcode 7 发行说明:

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.因为NSDictionary.Generator已经被定义为一个返回(key: AnyObject, value: AnyObject)元素的生成器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM