xcode 6.1.1 new class naming sctructure - xcode

I made a new class called "SignInView" by going to
CMD + n
iOS: Source
"m" Objective-C File
Next
File: SignInView
File Type: Category
Class: UIView
And what I get back are two new files:
UIView+SignInView.h
UIView+SignInView.m
I added these to my project target in build phases but these aren't picked up in my SignInView.xib when I set the main most view's custom class to "SignInView". I've tried "UIView+SignInView" as well but none of it is getting picked up. How am I supposed to add a custom class of this style name to Interface Builder?

As of Xcode 6, Apple has distinguished classes from other kinds of file. You want to go command+n -> Cocoa Touch Class and follow through there. Unintuitively, Apple does not offer the ability to create an Objective-C class within the 'Objective-C File' template.

Related

Unknown class in Interface Builder file. Xcode 6 and Swift

I started a vanilla master detail project with swift. If I add a new view controller and set the custom class, then the modules list is empty and it is not possible to choose a module. The error message "Unknown class in Interface Builder file." appears in the console if I run the code.
How can I setup the storyboard to know the custom class and module?
How it should be. The two classes from the template are just fine.
and how it is
I have to add customModule="Target_Name" customModuleProvider="target" to the interface builder source code. That is really annoying!
Update:
If I move the whole project directory to another, e.g. to the desktop it works. Looks like my directory with the name "Repository" is broken. Don't know why :(
I used to encounter the same issue, I finally found that the StoryBoard's Target Membership has been set incorrectly
.
I was getting the same problem but I discovered that I had inadvertently assigned a non-existing custom class to the view object managed by my view controller. So in the storyboard document view, I selected the badly configured view object, then in the identity inspector, deleted the bad custom class displayed for it (by backspacing and hitting return). That took care of the problem.
In my case, the custom class should be assigned to to the view controller, and not the view object managed by the controller.
I hit a similar issue when I changed the default Xcode project's UIViewController subclass to instead be a subclass of UITableViewController. (I made this change in the class source file, nothing to do with Storyboard).
I then went and typed my new class name into the IB "Class" field of the default "view" in the Storyboard. It would not autocomplete my class name, and then gave the Unknown class in Interface Builder file error when run.
The solution was to delete the default UIViewController object from the Storyboard, then add a new UITableViewController. Then, set that object's Class in IB to be your custom class.
It seems like the original question may be hitting this issue, as the first screenshot's class is ...ViewController and the second is ...TableViewController.
I've encountered the same issue and got it fixed. Reading this question gave me an idea to check the Identity Inspector further more and I found that the class Module should be inherit from target instead from a None module as I had.
Try checking the Inherit Module From Target checkbox and rebuild.
Hope it can help someone, obviously your problem has been solved since it was published in 2014.

Can't hook up IBOutlet or IBAction to a View Controller written in Swift after deleting the ObjC version

I created a project in XCode 5 and imported it to XCode 6 beta, then later decided that I wanted to rewrite one of the ViewControllers in Swift. So I first deleted the controller file (both .h & .m) and added the same class named controller within a Swift file extension. Now when I try to hook up an outlet and action from the Storyboard by ctrl-dragging from the widget to the file, I can't create new connections.
Is this a bug or do I need to do something else to get it to work?
Seems to be bug in Xcode 6. You can resolve this by Changing the ViewController Custom class in the identity inspector to some another class press return and again change the class to original class you want then press return.

How to get your custom content drawn in Interface Builder?

I watched the "What's New in Interface Builder" session video and tried to replicate the code that was showed but unfortunately when I assign a view to my custom class which has #IBDesignable I get 2 errors:
Main.storyboard: error: Live Views: Failed to update auto layout status: The bundle “swiftTest” couldn’t be loaded because its executable isn’t loadable.
Main.storyboard: error: Live Views: Failed to render instance of _TtC9swiftTest14ControllerView: The bundle “swiftTest” couldn’t be loaded because its executable isn’t loadable.
Later on in the video I saw that to have Live Views you have to make these steps:
1. Create framework
2. Create class
3. Mark as designable
How do I make the 1st step?
Thanks
As I understand it at the moment (prior to Xcode 6 Beta 3), #IBDesignable will only work from a view declared in a separate framework target.
However, I also struggled to add it because I had no "plus" button as described in various links (because the Hide Project & Target Lists arrow option was toggled off).
So, select your current project target, then just use the xcode menu options:
Editor > Add target...
Then select
Framework & Library > Cocoa Touch Framework etc.
By the way, to test #IBDesignable, this tutorial worked perfectly as a starting point:
http://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/
One small but important thing to note in that tutorial (if you follow it onscreen instead of following on to its full github code listing) is that your view class must be prepended/decorated with #IBDesignable, e.g.
class CustomView : UIView {...}
should be
#IBDesignable class CustomView : UIView {...}
You should make new framework as a target for current project and add your live views in this framework. On General tab on main target you will see your framework in Embedded Binaries section.
I had a project with live views working and at one point I also had these error messages. This went away for me when closing XCode and restarting, fwiw.
It is working very well (and easily) for me with Swift in Xcode 6 Beta 5.
I've confirmed that with Xcode 6 Beta 5 I did not need to add any frameworks (for example, Cocoa Touch framework option under frameworks in the dialog that appears when adding a new project target). Nor did I need to add IBDesignable.h to the project. Both seem to be outdated requirements as per the the weheartswift.com write-up linked in the initial answer to the question.
All I needed to do was:
Prefix class definition of my custom Swift class source file
with keyword #IBDesignable
Prefix vars I wanted to show up in IB Attributes Inspector with #IBInspectable (IB recognizes several common variable types).
Then, after assigning my custom component's (UIControl subclass) name to IB's "Class" name file (under Identity Inspector tab, in right pane) replacing "UIView" -- e.g. the class name of the UIView placeholder object I originally dragged onto the IB VC's view -- upon selecting my custom component from the Content View component list in IB, I saw all my custom class' inspectable items show up in the IB Attributes Inspector!! Very cool.
Note: At first XCode would only allow me to prefix one variable with #IBInspectable. It showed errors on subsequent ones. Then, suddenly it seemed to work, and no more problems after that. Not sure if it was a typo or just took Xcode awhile to re-index my project and pre-compile or parse the code.
I code about #IBDesignable & #IBInspectable,
firstly, I got two errors like you,
then, I change the code I wrote,
you can checkout the code from my github
Good Luck.

MonoTouch Designer Class Not Available In XCode

I am trying to build a custom TableViewCell, and so far I have created a xib file and laid it out in XCode designer. However, I cannot find my class in the drop down in identity inspector, and I cannot locate the generated class when in content assister.
Is there something beyond creating the xib in MonoDev to make my designer class available to XCode designer?
The (C#) class needs to have a Register attribute:
[Register ("MyClass")]
public class MyClass : UITableViewCell
{
}
Per Xamarin support:
When creating a custom UITableViewCell (and wanting to use the
designer), you have to use a bit of a "hacky" process to get the
code-behind file to work. You are going to want to add the class as a
iPhone (or iPad or Universal) UIViewController, change the superclass
of the class you just created to UITableViewCell. Make your changes in
the Xcode designer (delete view and add UITableViewCell), and then
make your changes in your code-behind file.
There is a great tutorial on how to do this here:
http://www.arcticmill.com/2012/05/uitableview-with-custom-uitableviewcell.html

Why can't I see a Managed Object Class file template in Xcode?

I created a .xcdatamodel Managed Object Model file in Xcode. I selected that file in Groups & Files. Then I go to File > New... > and nowhere in the iPhone Templates / Cocoa Touch Class templates I see the "Managed Object Class" file template.
Does anyone know what can be wrong?
I usually need to also select the entities for which I want to generate the class files.
In Xcode 4, select the entity in the xcdatamodeld, then choose Editor Menu > Create NSManagedObject Subclass
If you are wanting to subclass NSManagedObject then I would highly recommend talking a look at mogenerator (github). It will autogenerate the subclasses for you AND keep them in sync as you update your model. It also has the concept of machine classes vs. human classes so that you can add convenience methods, etc. without your code being stepped on each time you update your model.
I've seen this problem before as well. Solution for me was to click on a non-data model file (in Groups & Files) and then click back on the versioned data model file (and entity within it) and then try File -> New File. Alternatively, restarting xcode, selecting the data model file (and entity within it) and then trying File -> New File also worked for me.
Click On the top left where it says "Simulator 3.1.2 | debug". Change it to "IPHONE Device 3.1.2 (BASE SDK)... voila. (SAMS iphone in 24hrs?? lots of typos and incomplete procedures!)
Managed Object Class file template can be seen under "Core Data" section of new file creation option of XCode 4.
The following screenshot depicts it.
Thanks,
prodeveloper.

Resources