Custom Object/Class in XCode 4 Interface builder - ios

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.

Related

Include a custom class in Xcode 11 Object Library

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?

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?

Core Data Xcode 8

I started new project without core data checked and then I tried to put it in manually. So everything is fine but I have a question concerning Codegen in Data Model Inspector.
When I put class definition in Codegen field my class was redefined in appropriate to core data way so I deleted my old one. And after I saw extension of this new class where I could find all the properties.
So after I closed I couldn't find it in my project but I want to see it again.
How can I make it appear again?
When an NSManagedObjectModel is configured to generate code, it doesn't add that code to your project. Rather, it generates that code into your Derived Data, in the DerivedSources directory for the target the model is a part of.
In Objective-C, you can just use #import "ModelName+ManagedObjectModel.h" in your other code to gain access any of the entities for which code has been generated. In Swift, you don't even need to do that, you can just use the classes that were generated.
If you want to see the code for those classes, you can use Open Quickly (command-shift-O) and type in one of the class names. Xcode should take you right to the generated source code for it.

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.

Better way to recreate the class definition after modifying core data model?

When designing the core data model in XCode, you can automatically generate NSManagedObject subclass definitions (.m and .h files) by
Selecting the Entities
Choosing "Create NSManagedObject Subclasses" from EDITOR menu
After that, you may add a lot of code in these classes, what if you have to modify the data model setting a lot for some reason after that? To reflect these changes on the data model, is there any automatic way to do that? or you have to do everything manually.
Currently if I try to recreate these class definition from EDIT menu again(automatically), it will replace all the current files. All added code will disappear.
I really hope future version of Xcode can add a smart feature: automatically updating the default class definition without losing the added work. Maybe I am too lazy. :)
You're running into a common problem. You're pretty much stuck with that way of creating managed object subclasses with Xcode for the time being. Knowing that, you can either:
Design around it
For simple cases, you can use Categories to add functionality (though not state) to your NSManagedObject subclasses. Code in the category's file is obviously safe from being overwritten every time your data model changes.
Don't use Xcode
Mogenerator is a nifty tool designed to solve exactly that problem. It creates two classes for each entity instead of one, allowing Xcode to manage one while you manage the other.
It seems Apple has addressed the issue with XCode 7 : now it automatically creates the entity and a category of the entity with its core data properties. When you regenerate, it only updates the category, leaving your custom code in the entity class unharmed. See this link
You can create a class with different name and paste the generated fields into the old class

Resources