4

I'm looking to use the Objective-C library saxy to parse some XML into objects, however the method signature is:

+ (id)rootXPath:(NSString *)xpath toMany:(Class)toType nsURI:(NSString *)nsURI; 

I'm having trouble working out how I'd pass the Class object type as Swift does not seem to work with classes in this way. As a workaround I will probably make the domain model + a wrapper in Objective-C, but would be good to know if there's a way to do it in pure Swift.

I've tried the following, but I get a EXC_BAD_INSTRUCTION:

OXmlElementMapper.rootXPath("/route", toMany: Route.self, nsURI: "") 

and this which produces a syntax error:

OXmlElementMapper.rootXPath("/route", toMany: Route.Type, nsURI: "") 
2
  • did you solved your problem of passing Class to Objective C api from Swift? I am facing the same issue and I tried passing MyClass.self. But this doesn't seems to be working. I am using Xcode 7 Beta 6. Commented Sep 5, 2015 at 18:05
  • @dshah, afraid not. I haven't done swift in a long time. Commented Sep 6, 2015 at 1:23

1 Answer 1

5

MyClass.self is the correct way to reference a class, but perhaps you're missing @objc on the class?

See docs regarding interop

Sign up to request clarification or add additional context in comments.

1 Comment

You're quite right - the .self passing wasn't the problem. Looks like there is a bad cast coming out of that method.. thanks for the point in the right direction!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.