What is a class outlet and where is it? - interface-builder

I am trying to learn iPhone development and someone passed along the website www.appsamuck.com. On Day 1, the tutorial instructs the developer
We need to reference the label in our code so we can update the label
* In the document window "File's Owner"
* Click: Tools->Idenity Inspector
* In the inspector click the + under "Class Outlets"
* Change myOutlet1 to "countdownLabel"
* Change id to UILabel
* Click enter to make sure they commit
I really don't want to get hung up on this, but I can't find "Class Outlets" either when creating a new project from scratch or opening the zipped source code project. Is this just a difference in versions of Interface Builder? Where did it go?

Class outlets are used to connect objects defined in Interface Builder with ivars and properties defined in the source code. The feature you are looking for has moved since the tutorial was written.
In version 3.2.2, you want to click the File's Owner in the document window. Open the Object Inspector and click on the Info tab icon. Here you can set the class name. You can click the gray arrow in the class name text box or open the Library window. In the Library window click the Classes tab at the top then click the Outlets tab at the bottom. This is where you will see the list of outlets and can add or remove outlets.
Here's a screen shot that might make it easier to follow the steps:
http://skitch.com/kirbyt/n6wm3/classoutlets
Hope that helps.
-KIRBY

Yes, there are various flavors of the Interface Builder that comes with XCode. Especially 3.0 and tutorials written prior that version are a serious pain. You can find the Class Outlets in the Inspector pane. The icon that is blue with a little 'i', is where you should click on.

Related

manual option is not showing in Xcode 11 assistant editor and how to add IBOutlet?

I recently updated to Xcode 11 and some of its user interface changed. in older version of Xcode there was options of accessing files in assistant editor using automatic or manual. but in this version of Xcode I can't see any manual option in assistant editor. so I am not able to add IBOutlet and IBAction methods to particular storyboard.
so can anyone tell me how to add these actions and outlets, that would be great help. thanks
By pressing the above button, Xcode will split the view and allow you to select a custom file using the file tree at the top.
You are correct.
The Manual option is no longer visible. You can still achieve the same result by doing a quick open using Cmd+Shift+O then type the name of any file you want to open. Press the Alt key and the file will open in the Assistant Editor Window.
As others have noted the new add editor button allows you to add new editors and open files into them. You could file a bug report but you may want to consider that you're likely to get a "works as designed" type of reply.
You can always change or add new keyboard shortcuts to get the behavior you want by viewing the preferences key bindings area and search for the command you want to shortcut.
Note
You can still ctrl+drag from storyboard to the class by the Adjust
Editor button in the upper right of the storyboard. Then just select
Assistant Editor on the list. After which you can make IBOutlets/IBActions.
open your storyboard, hold option key and select the file you want
In the documentation outline of storyboard, try to choose the "correct" item, which you want to set up outlet connections. Say you want to set up an outlet connection for cell of table/collection view.
View Controller > Collection View > Cell > Content View > Image View.
Try to select Cell, "Content View" or "Image View", then check the jump bar of assistant editor, you're probably able to switch to the .swift file you want.
Reference

Xcode Interface Builder - "correct" way to delete/rename miswired IBOutlets / IBActions?

I am new to Xcode, working through Swift, so I'm not sure if what I am decribing is actually a bug.
When using interface builder and the assistant editor, I can create lables, buttons etc, and create Outlets and Action in the code with a control-drag.
So long as I am perfect, no problem. But I seem to run into problems if, for example, I make a mispelling of the object name. Or, I choose outlet instead of action. I can't seem to find a way to make a correction that does't seem to totally screw up the IDE. Even if I delete the object in the IB and the code, it seems to leave problems behind when I build. Or, if I try to delete the line in code and re-drag it, a new line of code is created, but the object seems to now reference the new name, and the old, now missing name.
Again, I am working with Swift --- Since I don't use/know Objective-C I don't know if there is a similar behavior using that language.
Appreciate any pointers. (Other than don't use the Interface builder / storyboards / Swift.)
Use the Connections inspector to break the connection. Then you can modify/delete the object and/or the code without having to worry.
The accepted answer is fine, but there are a few ways to do the same thing.
Method One
Right click the view in the storyboard and then click the little x by the referencing outlet.
Method Two
Right click the view name in the Document Outline. Then click the little x by the referencing outlet.
Method Three
Select the view on the storyboard and then click the Connections Inspector. Then you can click the little x to remove an outlet reference.
Extra References in Code
If you are getting outlet connections in code that you didn't add yourself see this answer.
You can find unused IBOutlets in the file in which they're declared by looking in the "gutter" of the source editor for an "unfilled hole".

Xcode keyboard shortcuts for go to class from xib and from xib to class?

Is there a keyboard shortcut for jumping from the current xib file to it's class (ViewController)? And back from it's class to it's xib file again?
I use ctrl-command-up/down all the time to to jump between header and source, be great to have one for the view xib also.
There are a couple of quick ways to get to the XIB associated with a class.
CTRL-5-↓-enter
This will open the jump bar to the current file. Assuming your XIB is named the same as your class -- which is usually good practice to do -- the matching XIB will be the next item in the list if you are in your implementation file, or two down if you are in your header file.
Alternately, you can open the XIB or StoryBoard associated with the file with one mouse-click if you have an IBOutlet.
See the outlet indicator next to the IBOutlet?
Click on it!
For additional Xcode shorcuts, a great resource is this PDF maintained in github:
http://cloud.github.com/downloads/Machx/Xcode-Keyboard-Shortcuts/Xcode_Shortcuts.pdf
I don't know if there's a keyboard shortcut for jumping from xib to corresponding class header file. But you can do that easily with a few mouse clicks:
Select a UI object in storyboard
Select "Identity inspector" in Utility Panel (3rd tab from left)
Click right-pointed arrow in the class name text field on top, which will take you to the header file
You can always go back and forth with two-finger swipe in Editor panel
Most shortcuts can be seen here:
http://cocoasamurai.blogspot.com/2011/03/xcode-4-keyboard-shortcuts-now.html
And although that would be an awesome one, don't think it exists.

Interface Builder won't let me double click on any objects in my .xib

Ok, I'm fairly new to Xcode, and I've created a few sample projects and added an Object from the Library into the document window, but when I double click on it to open the Inspector it beeps and won't open it. This used to work just fine, double clicking objects to open the inspector, now all of a sudden it doesn't work anymore. I restarted the computer but it's still doing it. Is there something I could have done which stopped this default behavior from working ?
The way i usually use interface builder is to ensure the inspector is visible (go to Tools > Inspector). Then, all you have to do is single-click on the object you want to view and its properties will be visible in the inspector.

Does Xcode have code navigation feature?

Does Xcode have a code navigation feature? Like unix's cscope type of tool which I can enter the name of a class and it will open the file for me? Or find out the caller of a particular method of a class? Or show the type hierarchy of a class?
command-shift-D (Xcode 4: command-shift-O) opens a Quick Open window where you can type a partial class name and hit enter to open the file. As far as more complex versions such as what Eclipse offers (method names, symbol names, etc), I don't believe anything like that is built into XCode.
In addition to the Quick Open window, there is the class browser. The class browser allows you to view the class hierarchy. The Class Browser can be found under the Project menu.
The "Jump To Definition" item is accessible through CMD + double click, which takes you directly to the relevant code
Also, you can "Jump To Documentation" by (Option or ALT) + double clicking on a class/method/property
Update:
Option + double click no longer takes you directly to documentation in Snow Leopard. Now it opens up a little documentation "bubble", with the option to jump to the documentation browser if needed.
If you Ctrl click a class name, method name or function name you will get a long meny where you can find the Jump to Definition item.
From XCode 4.4 upwards, you can find callers and callees by opening the "show related items" pop-up for a selected (highlighted) method:
Mark method in code (using your cursor or double click name)
Press Ctrl+1
Select "Callers" from the pop-up menu
You can also go View->Standard Editor->show related items or press the tiny button just left of the arrow buttons in the line just above the editor window (where it shows your currently selected file and method).
Also: select an identifier, right-click on it, and choose Find in Project > As Symbol (or Find in Project and choose Symbol as the search type) shows all symbolic uses, that is, declarations, definitions, and call sites.
There should opens up something like an element preview window or bubble when the user point to a method or item. The "Jump to Definition" change the users focus and take 2 steps to go to the target.
The relation window and context window in Source Insight is a good example,but I can't find them in Xcode and other dev tools for the mac.
By the way,the context window should have multiple layers to trace a deep referenced method like the split window in Xcode, not only one layer in the source insight.

Resources