ios – 将Xcode更新为7.0后出错

我正在 Swift中开发一个iOS应用程序.
当我将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
                }
            }
        }

有什么问题?你能帮忙吗?

解决方法

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

必须用Swift 2编写

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

从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:

06002

needs to be written as:

06003

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

但在您的情况下,实际上根本不需要显式注释:

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

因为NSDictionary.Generator已经被定义为生成器返回(key:AnyObject,value:AnyObject)元素.

以上是来客网为你收集整理的ios – 将Xcode更新为7.0后出错全部内容,希望文章能够帮你解决ios – 将Xcode更新为7.0后出错所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。