无法指定“String!”类型的值到'AnyObject'类型的值? - Xcode和解析

时间:2015-08-21 02:31:19

标签: xcode parse-platform

我正在运行以下代码:

    var inventario = PFQuery(className:"InventarioObjetos")
    inventario.getObjectInBackgroundWithId(toPassID) {
        (inventario: PFObject?, error: NSError?) -> Void in
        if error != nil {
            NSLog("%@", error!)
        } else {
            inventario["Categoria"] = self.nuevoCategoria.text
            inventario["Descripcion"] = self.nuevoDescripcion.text
            inventario["Tamano"] = self.tamano.text

            // Guarda la fecha de entrada
            let dateStringFormatter = NSDateFormatter()
            dateStringFormatter.dateFormat = "dd-MM-yyyy"
            dateStringFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
            let d = dateStringFormatter.dateFromString(self.nuevoFechaDeEntrada.text)
            inventario["FechaDeEntrada"] = d

        }
    }

inventario["Tamano"] = self.tamano.text行,我收到此错误:

  

无法指定“String!”类型的值到“AnyObject?”类型的值

2 个答案:

答案 0 :(得分:0)

只需将const int &投射到self.tamano.textAnyObject

答案 1 :(得分:0)

试试这个:

//... (make a connection)
mongo::client::initialize(); 
//...
my_connection = dynamic_cast<mongo::DBClientConnection*> (connection_string.connect(errmsg)); //connection_string is valid mongo::ConnectionString
....

实际上我会添加&#34;?&#34;在您的所有转化中,以防用户将其留空或检查

inventario["Tamano"] = self.tamano.text? (as! AnyObject?) shouldn't need this

当然println会弹出一个对话框或对最终用户做一些更有用的事情。