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.
Related
I have written my own class which inherits UIView. This is marked as #IBDesignable and properties I want to include in the interface builder are marked as #IBInspectable.
This works with no issues if I add a UIView to my interface, and then set its custom class .. eg it renders how I expect, and my properties appear in the attributes inspector.
How can I add my class however to the object library so instead of adding a UIView to the interface, I am actually adding an instance of my view, with only my exposed attributes, and my attributes set as their defaults?
Searched through countless questions and articles online and can only find reference to creating an Xcode plugin, which is no longer supported.
I am a multi language programmer and only use Xcode for iOS/Swift work, and this is a standard feature available in other IDEs I use (VS, Android Studio, and Delphi) - I am assuming I am missing something which is maybe underdocumented somewhere - or is this a case of an oversight/missing feature in the IDE?
I have created a framework from swift code, and it contains a few UIView subclasses. I can initialize it by code, but when I add it in storyboard, then when running I get an error:
Unknown class FindloFinalAugmentedRealityView in Interface Builder file.
Why is that? I was able to use this class in UI when it was not closed in framework
OK one change, I have found, that I need to specify a module for this to work. The only problem is that Xcode is not showing this module in list, I need to write it by my onw. Is this the only way this can work, or can I do something to make it show on the list?
I came across an issue yesterday where I am not seeing any of my custom classes in Custom Class or Module fields under Identity Inspector. This causes my app to break every time I run it, with error such as 'Unknown class x in Interface Builder file'
I browsed through tens and twenties of solutions (literally!) that were available in Stack and other sites. But none of them is helping at all!
Xcode 6 Strange Bug: Unknown class in Interface Builder file
"Unknown class <MyClass> in Interface Builder file" error at runtime
Unknown class FirstViewController in Interface Builder file
https://parse.com/questions/using-pfloginviewcontroller-and-pfsignupviewcontroller-with-storyboarding-throws-unknown-class-in-interface-builder-file-error
My learning has halted since yesterday due to small sh*** issue, has anybody encountered and resolved this issue before, please advise!
I also thought to re-install xcode but when I saw it was ~2.5G size, I again decided to give it a try and came to Stack!
Sorry, I forgot post how I could fix this issue.
Actually, it appeared to be a silly fix but I think it has to do with links. I simply changed the project folder location with a different name. I chose a folder name other than "iOS". Then it worked.
Hope it might help others.
Thanks
I've started trying some build-a-blog-reader tutorials and noticed that when I add a new UITableViewController file to control a new tableview, it doesn't give me all the methods.
All the tutorials walk me through adding a new file, selecting Cocoa Touch Class, then giving it a name and selecting UITableViewController from the presets. Yet my default file doesn't even have the viewDidLoad function by default, let alone all the methods that seem to flow in via these tutorial videos.
It seems I've done a few of these in the past and I actually had access to those, so did I turn something off inadvertently? How do I get it back? Or is this part of some new XCode update?
When you are adding a new Cocoa Touch class, make sure you're under the iOS section of the options, and not the OS X ones.
For some reason, even when you're working on an iOS project and you try to add a new file, the options will take you to the OS X files and not the iOS ones. So just go to "Source" under "iOS" and when you create your Cocoa Touch class from there it will correctly import UIKit instead of Cocoa and it will also include the necessary UITableViewController methods.
Select Cocoa Touch Class instead of Swift File when you create a new file.
I just started with the swift language and coming from java it looks great so far.
But I'm really missing something:
Eclipse had this great feature that when I added "implements XYZ" it provided me a function to automatically implement the necessary function stubs. This is a huge timesaver.
Xcode doesn't seem to have this feature, or am I missing something?
I found the accessorize plugin, but this seems only to work with Objective C..
Is there a solution?
PS. I'm using Xcode 6.1.1
NB: This answer is true for Xcode before version 9; in Version 9 Apple added the ability to automatically fix up missing protocol methods; see Guy Daher's answer.
I just created an iOS project, and headed into my UIViewController.swift file. There I declared that it implemented UITableViewDelegate:
class ViewController: UIViewController, UITableViewDelegate {
Now when I go into the body of the class, and start typing "tab...", I see the appropriate autocompletions:
Hitting Enter then inserts the function stub, with the cursor placed ready to code.
That's just the way Xcode autocompletes protocols (or inherited class methods.) If you want to do all of them at once, I don't think it's possible, sadly. But you can always Cmd-click or Option-Cmd-click (which uses a secondary editor window) on the protocol name to jump to its definition, which is basically a list of all its methods you can copy and paste into your code. You'd need to tidy up a little from there, but not much.
Xcode 9
Xcode 9 now supports conforming to protocol methods via a "fix it". It will automatically fill the missing methods for you. This was announced in WWDC 2017.
Update: This doesn't seem to work for protocols defined by you, unfortunately.
Xcode 9, takes care of implementation of mandatory methods of Swift Datasource & Delegates.
Look at these snapshots, with example of UICollectionViewDataSource:
Indicating warning to implement protocol methods:
By clicking on 'Fix' button, it has added all mandatory methods:
Alternate Option:
You can use a keyboard short key: Ctrl + Option + Command + F to fix all issues at once.