休息套件 RKMappingOperation 不起作用

Rest kit RKMappingOperation do not work

Rest kit RKMappingOperation 不工作

这是我 运行 的代码。它应该在 CvvName 对象中创建数据。但它不起作用。如何让它发挥作用?

class CvvName: NSObject{
    var firstName = ""
    var lastName = ""
}


class CvvMappingProvider: NSObject
{
    class func nameMapping() -> RKMapping
    {
        let resultMapping : RKObjectMapping = RKObjectMapping(forClass: CvvName.classForCoder())
        resultMapping.addAttributeMappingsFromDictionary(["firstName":"firstName", "lastName": "lastName"])
        return resultMapping
    }
}

func doRestKit()
    {
        var theMapping:RKMapping = CvvMappingProvider.nameMapping()
let theRepresentation = [["firstName": "firstName01"] ,["lastName": "lastName01"] ]
        let theDestinationObject = CvvName()
        let theMappingOperation = RKMappingOperation(sourceObject: theRepresentation, destinationObject: theDestinationObject, mapping: theMapping)
        do {
            let theTry = try theMappingOperation.performMapping()
            //theMappingOperation.start()
        }
        catch is NSError {
            // Unexpected error!
        }



 print("theDestinationObject \(theDestinationObject) + \(theDestinationObject.firstName) + \(theDestinationObject.lastName) +")
}

它打印空字符串

theDestinationObject <ap01.CvvName: 0x7c20f260> +  +  +

我希望它打印值

theDestinationObject <ap01.CvvName: 0x7c20f260> +   firstName01 +  lastName01 +

看起来问题出在您提供的源数据中:

let theRepresentation = [["firstName": "firstName01"] ,["lastName": "lastName01"] ]

这是一个字典数组,但您实际上应该提供一个包含所有详细信息的字典,因为该操作需要一个输入项和一个输出项。考虑:

let theRepresentation = ["firstName": "firstName01", "lastName": "lastName01"]