将Xcode更新为7.0后出错 [英] error after updating the Xcode to 7.0

查看:83
本文介绍了将Xcode更新为7.0后出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Swift中开发一个iOS应用程序。
当我将Xcode更新为7.0时,我在swiftyJSON中遇到错误。

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?

推荐答案

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

必须用Swift 2写成

must be written in Swift 2 as

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

从Xcode 7发行说明:

From the Xcode 7 release notes:


模式中不再允许使用类型注释并被视为边远声明的b $ b b部分。这意味着之前的代码
写为:

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()

需要写成:

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 { .. }

因为 NSDictionary.Generator 已被定义为生成器
返回 (键:AnyObject,值:AnyObject)元素。

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

这篇关于将Xcode更新为7.0后出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆