I would like to check in swift whether an object is a member of a specific class. However the class is stored as property of an another object, in this case RKRequestDescriptor, a class of the RESTKit framework. RKRequestDescriptor has a property defined, which stores a class object in its objectClass property.
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 test against and since this is a subclass of RESTKits RKObjectManager, there is an array with requestDescriptors.
Now I am having a hard time in swift to "translate" the above objective-c code. I tried:
for var thisDescr:RKRequestDescriptor in self.requestDescriptors {
if let newObj = obj as thisDescr.objectClass {
That doesn't work. Xcode throws errors. To begin with it doesn't "like" in-the loop ("expected condition in for statement). So it to:
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 is really harder than I thought to "translate" objective c to swift :-(