This question already has answers here:
Xcode 6 Bug: Unknown class in Interface Builder file
(52 answers)
Closed 5 years ago.
I am programming the ToDoList Objective-C Tutorial from Apple, but try to do it in Swift.
(Tutorial)
Now that I am ready, when I run the Application, I get the error:
Unknown class AddToDoItemViewController in Interface Builder file in Swift.
In this thread, somebody solved a, as I think similar Problem with [MyClass class] in Objective-C. Is there a similar way to do this in Swift?
I found that on a lot of my Swift Controllers there's a new Module Option which was set to None
So to fix it just set the Class to a different one and then set it back. That gave me this
A similar line in swift would be AddToDoItemViewController.self. All that really matters is you call your view controller from swift code so the linker knows to include that file.
I ran into this situation when I made a mistake and used a different name in the #OBJC statement than my declared class name.
Related
This question already has answers here:
Class PLBuildVersion is implemented in both frameworks
(7 answers)
Closed 6 years ago.
This is the error I'm getting in console when I run the app.
objc[4391]: Class PLBuildVersion is implemented in both
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices
(0x112a1d910) and
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices
(0x112847210). One of the two will be used. Which one is undefined.
It's not a error,it print just when you test your APP on simulator. The reason is objc uses the same namespace for your App,when class have the same name,The behavior of objc runtime is unpredictable. One possibility is that the class of any program will be loaded.
This question already has an answer here:
What is other option available in swift instead of refactoring and renaming class or attribute name?
(1 answer)
Closed 6 years ago.
I am working on swift project.After 1 month I need to refactor the code as we have done in objective c. I need to change some class names, properties and method names. But problem is that when I go to refactor the code but It showing me an error.
Error is "Xcode can only refactor C and Objective-C code."
Is there any way to refactor the code because there are 50+files to change the code.
Thanks in advance
Unfortunately, no. We're stuck with "Find>Find & Replace in Project".
I am very new to iOS who is trying to use swift in objective-c. I created a swift class in the objective-c project and i am able to call that class from an objective-c view controller.
The problem is if i make any changes in the swift code, it doesn't seem to be available immediately for objective-c class to access. Each time i change something in the swift class, i will have to build the project and only then it seems to be available in objective-c.
Is there a configuration that i am missing or it is expected to work this way by design?
Please read this explanation from apple. Read the sub-heading "Importing Swift into Objective-C". The generation of header files might be the explanation for your issue.
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-ID122.
I am trying to subclass my UIButton on my Storyboard with a custom swift class that should show the button as a custom Hamburger Button.
I am getting this warning and not seeing the Hamburger button being rendered in Interface Builder, although it will intermittently work.
The Custom class is called NTHamburgerButton, I don't know why the string on characters is appearing before the class name.
IB Designables: Using class UIButton for object with custom class
because the class _TtC6CProjectName17NTHamburgerButton does not exist.
I've encounter the same problem, and I found an answer from other question:
enter link description here
I just Refresh All Views
It works to me. Hope it helps you too.
This question seems to be getting some attention again so I'll give an update.
This issue existed in a Obj-C and Swift mixed project. So the Class in question was a Swift Class.
When making Swift classes available in Obj-C, you can use the following syntax
#objc(NTHamburgerButton) public class NTHamburgerButton : UIButton {}
Otherwise in your {Project-Name}-Swift.h file that Xcode Creates you will see that it generates these unique class names like that from the question.
The only real issue here was that the NTHamburgerButton.swift file was not being included in the Product I was looking at the at time, but if I switched targets, it worked fine. Thus the intermittent issue.
For me both solutions of Codermonk and specialvict was necessary, but not enough.
I also had to turn on Inherit From Target in Interface Builder:
This did the trick for me.
I struggled with this error in Xcode 11 even after applying the other solutions given.
In my case, I had my own #IBDesignable class residing in the main module (so, not from a CocoaPod or other external module). Yet even when specifying an objc(ClassName) for my view class, the auto generated class name was still being used by Interface Builder at build time.
Finally, I removed the module name and module inheritance in IB and that removed the error and got the view preview rendering:
So, the complete solution for me was:
Declare an Objective-C class name for the Swift class
Configure the class in Interface Builder as shown above
Both are seemingly required in Swift as of Xcode 11. Notably, I had no issues with the view at runtime despite removing the module reference. I am also unsure how this solution would look for views imported from other modules.
This started happening to me in Xcode 12.1. Thus far, simply un-checking then re-checking the "Inherit Module From Target" in Interface Builder seems to have solved the problem.
This question already has answers here:
How to use Namespaces in Swift?
(9 answers)
Closed 5 years ago.
Hy guys,
Do you know how can I create a module(namespace) in swift ? For example in C# we have namespace keyword, but in Objective-C there is no such thing, there we named our classes with the prefix of the folder they were located in. Shall I use the same approach in swift or do you know some other way to achieve namespacing in swift.
Thank you!
You can achieve it by using Frameworks which is newly introduced in iOS 8 for namespace-ing, if I am not mistaken.
I think I will either rename my classes to have a prefix of two capital letters like NSString, UIView and other classes from Objective-C do or I will wrap them in structs.
Thank you for your comments.