0

I have a build error when trying to subclass a custom Objective-C class (a subclass of UIViewController) in Swift.

When I try to subclass in Swift, I get the build errors in the picture below. All of them relate to the use of the word class as an argument in the OCMapper library (where I've opened an issue as well).

Some more notes:

  • In the project, I both import and use Objective-C code in the Swift code and import and use Swift code in the Objective-C code.
  • I import the compiled Module-Swift.h only in .m and .mm files and forward declare classes that I need in .h files.
  • I've attempted to create a Module-Swift-Fixed.h class where I forward declare and/or import the custom Objective-C class headers (as recommended here), but that hasn't made a difference.

many build errors build error

Has anyone seen anything like this before or have a solution?

Community
  • 1
  • 1
Jesse Pollak
  • 1,600
  • 1
  • 15
  • 20

1 Answers1

1

I have as yet not been able to trace where in the language spec this is documented, but I suspect you have come across the same problem that I recently faced in objective-c since moving to Xcode 6.4.

I had a message (method) defined as follows

- (BOOL)canProcessClass:(Class) class {
    return [class isSubclassOfClass:[NSSet class]];
}

with the same compile error as you mentioned Expected identifier. The fix was simple - just rename the the class argument to something like classToProcess. Which would give you the following

- (BOOL)canProcessClass:(Class) classToProcess {
    return [classToProcess isSubclassOfClass:[NSSet classToProcess]];
}

Hence just rename the arguments in your Swift code to not use the (key)word class and you should be fine.

If anyone can point me to the language spec that documents this I would really appreciate it. As far as I'm aware you shouldn't use Class, but I haven't able to find anything about class except the obvious that it is a message (method) available on classes.

carnun
  • 150
  • 11