1

Unfortunately, I have a class defined in Objective C (Class.h, Class.m) and another class, with the same name in Swift(Class.swift).

I have a bridging header, where I import the class

#import "Class.h"

Now, I want to create a method that returns the class from Objective C. Is there a way to specify that I want to use the Objective C class instead of the swift one, or should I start renaming my classes?

1 Answer 1

4

Rename classes. I am not 100% how Swift classes that are not tagged @objc are treated, but nothing good can come of having two classes with the same name, even if they're written in different languages. If the Swift version is visible to the Objective-C side, you have a definite problem, and you cannot be sure when instantiate a Class which one you will get. It could theoretically change on every run of the program, though in practice the class loader is probably too deterministic for that to occur.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.