Class comparison in quick

I want to quickly check if an object is a member of a certain class. However, the class is stored as a property of another object, in this case RKRequestDescriptor, of the RESTKit class. RKRequestDescriptor has a specific property that stores a class object into its objectClass object.

So, in objective-c, I have something like:

  for (RKRequestDescriptor *thisDescr in self.requestDescriptors) {
    if ([thisDescr objectClass] == [obj class]) {
        ...

      

where "obj" is some arbitrary object to check, and since it is a subclass of RESTKits RKObjectManager, there is an array with requestDescriptors.

Now I find it very difficult to quickly translate the code above objective-c. I tried:

     for var thisDescr:RKRequestDescriptor in self.requestDescriptors {
        if let newObj = obj as thisDescr.objectClass {

      

This does not work. Xcode is throwing errors. To begin with, it doesn't "like" it in the loop (the "expected condition for the for statement"), so it:

    var thisDescr:RKRequestDescriptor?
    for index in 0..<countElements(self.requestDescriptors) {
        thisDescr = self.requestDescriptors[index] as? RKRequestDescriptor
        if let newObj:AnyObject = obj as? thisDescr.objectClass {

      

but still no luck. It's really harder than I thought to "convert" target c to swift: - (

+3


source to share


1 answer


Fast Acting Equivalent [thisDescr objectClass] == [obj class]

:



thisDescr.objectClass === obj.dynamicType

      

+3


source







All Articles