ios – 将Xcode更新为7.0后出错

前端之家收集整理的这篇文章主要介绍了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)元素.

原文链接:https://www.f2er.com/iOS/335449.html

猜你在找的iOS相关文章