So according to this tutorial
"Xcode uses the product name you entered to name your project and the app. Xcode uses the class prefix name to name the classes it creates for you. For example, Xcode automatically creates an app delegate class and names it HelloWorldAppDelegate. If you enter a different value for the class prefix, then the app delegate class is named"
However when I create my project, it doesn't create the files with my project name. So instead of "ProjectNameAppDelegate.h" I just have "AppDelegate.h". Is there a reason why XCode wouldn't create the proper files I need and how do I fix it?
I also don't have a ViewController.xib file which most online tutorials say I should have. I do have a "MainStoryboard.storyboard but I'm not sure if that counts as the same thing.
The tutorial you mentioned is on an old Xcode. The latest Xcode wont create appDelegate and ViewController classes by prefixing project name as you said like ProjectNameAppDelegate.h. It simply create AppDelegate.h only. It is not a bug.
In the above figure you can see that i have selected Use StoryBoards, So Xcode wont create Xib files for your viewController instead it will create a storyboard only. Here you dont want xib . Storyboard is replacement for the xib. If you unselect that feature you will get xib back. As a beginner you should go through several tutorial that uses both xib and storyboards.
Adding to Anil's answer, Storyboard is a replacement for the old .xib files.
Related
Maybe I'm just doing something wrong here but I've ran into an issue that I can't find a solution for. Maybe someone has seen this?
Using Xcode 6, I create a new project with Objective C & Storyboards.
In the interface builder view, I place a text field on the view that comes with the storyboard and bind it to the 'Shared User Defaults Controller'. Everything works fine.
I add a second view controller. This creates a new scene. I place a text field on this view and bind it to the 'Shared User Defaults Controller' and here's the issue:
A 'User Defaults Controller' gets created in the scene. If I expand the dropdown list for 'Value' 'Bind to', there are now 2 'User Defaults Controller' objects in the list. The binding doesn't seem to work as the value doesn't get stored in the preferences file.
Did I do this wrong? Or is it a bug in OS X storyboards on Xcode 6?
Yes, it is a bug in Xcode 6 with Storyboards. I found a workaround: edit the storyboard manually.
First bind an item to the shared preferences on one scene. Then close the storyboard and edit it as source (edit the xml directly).
Find the line representing the shared user preferences instance. It should look something like that:
<userDefaultsController representsSharedInstance="YES" id="a6K-Ly-rL1"/>
You can then copy this line in each scene, in the objects array, in the xml directly.
You must edit the id of each shared preference instance added manually because a storyboard file cannot have more than one object with the same id. Simply changing one character at random in the id string is enough.
My workaround is to add an NSObject to the storyboard scene and use my custom class
#objc(SharedUserDefaultsControllerProxy)
public class SharedUserDefaultsControllerProxy: NSObject {
lazy var defaults = NSUserDefaultsController.sharedUserDefaultsController()
}
then bind on self.defaults.values.
This question already has an answer here:
Changing xib name [duplicate]
(1 answer)
Closed 8 years ago.
I am using iOS 5 and Xcode 4.2. In my project i have a UIViewController with xib. Now i want to give seperate name for UIViewController and xib.
Is it Possible?
After changing the name of UIViewController the controllers showing warning and i can not connect connect controllers to this class.
Within your header file (SomeViewController.h), highlight the class name and from Xcode menu > Edit > Refactor > Rename
And follow the on screen instructions.
Good Luck.
Renaming a class file names and interface files are possible. However, renaming class name by refactor option on Xcode is appreciated than doing it manually.
For refactoring GOTO: "symbol navigator(next to project navigator)">>
right click on your file name >> "REFACTOR">> RENAME.
Having different names for classes and interface do not bring up issues, however its the standard to keep the interface file name same as that of the corresponding class files.
You just change the .h and .m file names by click on those files. What ever new name you gave to those files use that name while importing those files other than that don't change those name any where. try it once..
After changing the name of UIViewController the controllers showing
warning and i can not connect connect controllers to this class.
Find the code where you're instantiating the view controller. It should look something like:
MyViewController *mvc = [[MyViewController alloc] initWithNibName:... bundle:...];
When you find that line, look at the values you're passing for the nib name and bundle. Chances are, you'll need to change the nib name that you're passing in. Either you're passing an incorrect name, or you're passing nil. If if the first case, simply correct the name. If you're passing nil, again, just change that to reflect the actual name of the .xib file. (It's common to use nil because UIViewController will use the class name as the nib name if you pass in nil, so nil is a handy shortcut.)
Sorry if my question looks noob, im new in objective c programming. Im using 4.6 xcode, and when i started to make new built in tab project, then I started to add new UIViewController subclass file, i cant find it. If the template is changed, which template that can provide 3 file (.h, .m, .xib) same with UIViewController. Answer will be appreciate. thanks
Choose the Objective-C class template from the Cocoa Touch section. On the next page, select or type UIViewController in the "Subclass Of" field. Make sure "With XIB for user interface" is checked.
When you first create an Application in XCode, at it's lowest level it creates the AppDelegate.h/.m and a MainWindow.xib
Once you start modifying the Xib to best suit your design needs - is it best practice to move away from the AppDelegate as the initial Controller or is it always better to create a new WindowController to use with the MainWindow.xib ??
Fritzables
The AppDelegate class cannot be used as a view controller, if that's what you're asking. Your AppDelegate class should be creating an instance of your main View Controller, which loads your main .xib file. Unless you're referring to defining the main Xib in your target configurations, but that's pretty old school.
Are you constrained by the version of iOS you need to support? Because you could avoid using .xib files altogether by using storyboards if you can use iOS 5.0 and up.
Well good question. To me app delegate always has been a initial step to define a project that I create. There are many use for delegates but that is another subject. If you look at the apple doc's related to this subject (over view section) in the following link, there is a great explanation of what is the function of the app delegate there. To answer the question you ask, it is always a good practice to leave the app delegate and create a new controller and execute whatever function you want in there. Here is the link to apple do's and I hope it clears up everything for you my friend. Happy coding.
http://developer.apple.com/library/ios/ipad/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
i am currently starting to learn Xcode and objective-c and i am reading three different books on that topic currently. All of these books refer to a file called "AppDelegate" (My_First_ProjectAppDelegate.m, My_First_ProjectAppDelegate.h) which are said to be "created with the Project" (i am creating a "Cocoa Application"). These files are not present when I create a new Project. I seem to be not the only one having this problem (see http://pragprog.com/titles/dscpq/errata ).
Is there any more information about AppDelegate? What is the current practice on how to deal with a missing Appdelegate? i am using Xcode Version 3.1.4 on Mac OSX Leopard.
AppDelegate is nothing more than a common NSObject class with needed connections in MainMenu.xib. You can easily recreate your own:
Create a class, name it AppDelegate
Open MainMenu.xib and add NSObject object to object palette
In object inspector's Identity tab (the last one) set object's class to AppDelegate (you should get autocomplete)
Ctrl+drag from Application object to your newly created AppDelegate object and choose "delegate" from opened panel.
As I recall, only the iPhone templates were providing delegate classes by default. This is not a huge deal, but I can see how you would be concerned if you are just learning. Are you sure what you are reading is relevant to MacOS applications and not Iphone?
You can always create your own delegate class manually. You just create a class as you normally do, then set it as the delegate for NSApplication in Interface Builder.
I think the confusion comes from the version of XCode you are using.
Xcode version 3.2 changed the default behavior when you create a new project: it now creates an AppDelegate for your project. I can't remember what the earlier versions did, but it was different.
As Eimantas says, if you want to use an AppDelegate then you can just create one following the steps he describes.