繁体   English   中英

类型'Int32'不符合协议'AnyObject'Swift?

[英]Type 'Int32' does not conform to protocol 'AnyObject' Swift?

我有一个NSObject的Model,子类,如下所示。

class ConfigDao: NSObject {
    var categoriesVer : Int32 = Int32()
    var fireBallIP : String =  String ()
    var fireBallPort : Int32 = Int32()
    var isAppManagerAvailable : Bool = Bool()
    var timePerQuestion : String = String ()
    var isFireballAvailable : Bool = Bool ()
}

我已经下载了NSMutableData并使用NSJSONSerializationJSON

我的代码是

func parserConfigData (data :NSMutableData) -> ConfigDao{

        var error : NSError?
        var json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary

        var configDao : ConfigDao = ConfigDao()

        println("Print Config \(json)")

        configDao.categoriesVer = json["CategoriesVer"] as Int32
        configDao.fireBallIP = json["FireBallIP"] as String
        configDao.fireBallPort = json["FireBallPort"] as Int32
        configDao.isAppManagerAvailable = json["IsAppManagerAvailable"] as Bool
        configDao.timePerQuestion = json["TimePerQuestion"] as String
        configDao.isFireballAvailable = json["IsFireballAvailable"] as Bool

        return configDao

    }

我收到错误

Type '`Int32`' does not conform  to protocol 'AnyObject' 

我在哪里使用Int32

下面的图片

在此输入图像描述

谢谢

Int32无法从Objective-C NSNumber自动桥接。

看到这个文件

以下所有类型都自动桥接到NSNumber:

  • 诠释
  • UINT
  • 浮动
  • 布尔

所以你必须这样做:

configDao.categoriesVer = Int32(json["CategoriesVer"] as Int)

顺便说一句,为什么你使用Int32 如果您没有任何具体原因, 则应使用Int

暂无
暂无

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

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