Include a custom class in Xcode 11 Object Library - ios

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?

Related

Cant use framework view in storyboard

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?

What is the module field in the identity inspector used for?

What is the module field in the identity inspector used for? In Xcode, there is a field under the class name when you switch to the identity inspector. I understand the class field is for selecting the class but not too sure what the module field is for. you can see the below screenshot
This is taken from the 2014 WWDC discussion
Now, you may notice there's a new module field here.
Another great way that Swift improves the coding experience is by
associating classes with the modules that they are declared in.
That allows you to use short, comfortable class names while still
ensuring that your classes won't collide across targets and projects.

IB Designables gives strange warning when using a custom class

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.

Is there any class in MvvmCross that inherits from ActionBarActivity?

I'm developing an App with Xamarin.Android (aka MonoDroid), using the great MvvmCross Framework. The application uses Fragments, and need an ActionBar.
I've noticed that the MvxFragmentActivity inherits from MvxEventSourceFragmentActivity, and this last inherits from FragmentActivity, which has no ActionBar support. To support ActionBar, i need a class that inherits from ActionBarActivity, wich is included in the Support Library, and inherits from FragmentActivity.
So, my question is: Is there any MvvmCross class that Inherits from ActionBarActivity?
If not,
Can I just create a MvxEventSourceActionBarActivity and a MvxActionBarActivity that inherits from the first one, with just the same code of the MvxEventSourceFragmentActivity and MvxFragmentActivity just changing the inherits?
The basic answer is "No. There's no existing class. But I f you want to add binding to any Activity, then you can do so using 2 layers of inheritance - adding first an eventsource and then an Mvx layer"
There is a bit more detail about this in a few questions - eg ActionBarSherlock with latest MVVMCross
For the latest android support library, there is one issue to be aware of currently - when building binaries you currently either have to choose the mono library which gives you compatibility with play services or you have to choose the new Xamarin component which gives you the latest support lib - see MvvmCross - trying to use Fragments AND latest support lib results in linking problems and https://bugzilla.xamarin.com/show_bug.cgi?id=15205

Custom Object/Class in XCode 4 Interface builder

Im using Xcode 4. In interface builder of my project, I pulled a custom Object (gold cube) from library. I named its class as MyController and did the same for its label. I saved these settings then.
But I'm not able to write this class to the project's class files. I mean I cannot generate class file from this custom object I pulled from the objects library. I wanted it to inherit from NSObject alone and I want to tie up some outlets.
How do I do this in Xcode 4? Please help. The help documentation regarding this topic is not good.
The cubes you see in Interface builder for objects are not there to generate code, they are there to represent objects.
You need to create the class normally and then configure the block to be an object of this class.

Resources