Is there a way to see object names in debug view hierarchy? - xcode

The debug view hierarchy is a great way to view they different layers that make up the UI, but as far as I can't tell there is no way to see what outlet reference names the objects have. They are simply referred to as what type of object they are. For example, a button is just refered to as UIButton rather than the name of the outlet. Yes, it's possible to see in what viewController it resides, but it' not foolprof and it can still be very hard to track down certain objects.
So, is there a way to see what the reference outlets of the objects are called?

UIView.accessibilityIdentifier does that trick.
For NSLayoutConstraints, its description in warning log (or po constraint) contains more details after set UIView.accessibilityIdentifer.
Before set accessibilityIdentifier, it's something like
<NSLayoutConstraint: 0x6000037766c0 UILayoutGuide: 0x600002d6c620'UIViewSafeAreaLayoutGuide'.trailing == UILabel: 0x7fee70712780.trailing + 132 (active)>
After set accessiblityIdentifier,
<NSLayoutConstraint:0x6000037766c0 UILayoutGuide:0x600002d6c620'UIViewSafeAreaLayoutGuide'.trailing == First-ID.trailing + 132 (active, names: First-ID:0x7fee70712780 )>
For view debugger, you can check accessibilityIdentifier as follows

No, there is not (unfortunately).
The information is not maintained at runtime to my knowledge, so you also won't be able to use lldb from Xcode's console to figure it out.
Probably worth a feature request to Apple!
https://feedbackassistant.apple.com/

Related

Cocoa Data Binding - One view object bound to two 'enabled' properties

Using Cocoa Data Binding I have bound a button's 'enabled' property to two separate 'Model Key Paths' (Enabled and Enabled2).
The idea is that the button will become enabled if either of these properties is true.
Unfortunately, it only works if both become true.
Can anyone help me change this logic from AND to OR?
Cool question-- I'm going to make a shot in the dark, I can't confirm it for you until tomorrow, but try this maybe?
Create a new property, enabledOrEnabled2 (maybe with a better name).
Override the getter (-(BOOL)enabledOrEnabled2) for this property,
to just return (Enabled || Enabled2)
Set the Key Path to be enabledOrEnabled2
I'm a little skeptical if this will work because Cocoa Bindings work by using KVC and KVO. So atm, your view controller is observing your Enabled and Enabled2 properties. What happens during runtime is that Cocoa will override your properties w/ their own KVO properties that look and act just like you think they would. Except the setters have been overridden, to send out notifications to observers.
I think the problem with my solution is that -(void)setEnabledOrEnabled2 will never be called, because you will only be setting your Enabled and Enabled2 properties. Therefore, the Cocoa overridden -(void)setEnabledOrEnabled2 will never notify your observing view controller
EDIT: Just read #stevesilva's comment, and didn't even know that dependent keys was a thing. Looks like you could definitely implement it this way if you wanted to
Actually, a first-thought hack would be to switch from overriding the getter (like I first recommended), and instead override the setters: -(void)setEnabled and -(void)setEnabled2, and add a line, something like: _enabledOrEnabled2 = _Enabled || _Enabled2. That way anytime you set your two BOOL properties, it will update enabledOrEnabled2, which will then send a notification out to it's observer, your view controller.
But now that I've written that out, I was wondering about the second part of Cocoa Bindings, KVC to modify the model whenever the view sees changes.
And because you are actually using Bindings on an Enabled state-- I actually don't think you should be using Bindings. This is because the view can't actually be modified (i.e, you can't modify the enabled state of a button). So you wouldn't ever need to use KVC to change enabledOrEnabled2, you only need your button to observe BOOLs to know if it should be enabled or not.
So scrap everything I said thusfar--
What you should do is still modify the setters ( -(void)setEnabled and -(void)setEnabled2 ), and before setting the ivar you should add a line:
[self.button setEnabled:(_Enabled || _Enabled2)];
That should do the trick for ya :)
Sorry for rambling a bit, I feel like the info I wrote initially may be helpful so I decided not to delete it

How to create multiple windows using "command + n" in non document based application

Is there a way to create/enable having multiple windows using "command + n" in a non document based application? I want to have unlimited instance of that window (not actually unlimited, but might be 6-7 instances) using command + n
Or I have to create a document based app and port all my code in new project template is the only solution?
I can see the menu button for "New" is disabled right now.
A few ways to do this.
First connect the New menu item to an IBAction method.
Name the method whatever makes sense to you.
Next, you will want to add some kind of property to your controller ( app delegate for simplicity ) that is basically a window stack only storing a reference to each window or window controller. NSMutableArray should do nicely.
Now you can do the next part a few ways, but I would recommend creating an NSWindowController subclass with a nib/xib (especially if these windows will have the same basic things in them).
Do what you want in the nib file.
Now in your IBAction method, create a new instance of your window controller class, add it to your mutable array. Tell it to load its window.
You only have to decide if the controller should be removed from the stack and set to nil if its window is closed.
Many ways to handle that, and up to your design to know what is correct.
Try this :-
NSWindowController *yourWindow=[[[[yourWindowController alloc]init]retain]autorelease];
[yourWindow loadWindow];

Is there a way to jump to code for outlets / actions in Xcode (4.4)?

I've been looking at an .xib that someone else set up and it would be really convenient if I could, say, double-click on the properties / methods associated with outlets / actions to jump to the actual code where those are declared / defined. I've tried everything I can think of but so far to no avail. Am I right that there's no way to do that...?
To illustrate, say I've got a UIButton for doing a "reset". When I right-click on that in the Interface Builder (this is Xcode 4.4) I might see that there's an associated outlet called "resetButton" and an action mapped to "onReset". From what I can tell, the only way to find the associated code is to manually type those property / method names into a search box and look for that in the associated .h / .m (e.g. using the Project Navigator search). In some cases, I'm hitting the same names multiple times in different files then having to figure out which one is for the object that I'm actually interested in.
Is there some trick that I could use to jump to the code that I'm not seeing?
ETA

NSApplication orderFrontStandardAboutPanel: Making my about panel slightly less standard

What are my options, if any, of adding additional, arbitrary data to the standard Cocoa about dialog that is displayed by an NSApplication when it receives a orderFrontStandardAboutPanel message.
If you add a file named Credits.rtf to Resources the contents will automatically be used in the expanded standard about panel and you can put whatever info you want in the file. It will still pull the standard copyright, version info, etc from the info.plist. It is the easiest way I know of to add arbitrary info, otherwise you pretty much will have to roll your own about panel.
-[NSApplication orderFrontStandardAboutPanelWithOptions:]
Expanding further on the answers from Darrell Root and theMikeSwan above, Apple's documentation for the credits property of NSApplication.AboutPanelOptionKey states:-
The value of this key is an NSAttributedString displayed in the info
area of the panel. If not specified, AppKit then looks for a file
named “Credits.html”, “Credits.rtf”, and “Credits.rtfd”, in that
order, in the bundle returned by the Bundle class method main. The
first file found is used. If none is found, the info area is left
blank.
Expanding on theMikeSwan's answer, by accident I found that if you add a file named Credits.html to the Resources folder, it's contents get used in the expanded standard about panel. In fact Credits.html appears to override a Credits.rtf.
So your choice whether to use html or rtf format, or wire up "About" to a completely different custom window controller.

What is the name of this Mac OS X control?

Does this control have a name? Or is it just a bunch of simple controls merged together? If so, what controls are they?
http://img8.imageshack.us/img8/3002/picture2xrb.png
It looks like an NSTableView with an a custom cell type and no column header. Have a look at the documentation for NSTableView's tableView:dataCellForTableColumn:row:. For columns which have the same type for all rows you may also set the cell class in interface builder.
I doubt the search box is part of the same control.
You could open the Application's Nib file to see what is in there. Look inside the application bundle. If the application is called Example then you should be able to find the Nib at Example.app/Contents/Resources/English.lproj/MainMenu.nib.
The best tool for investigating this is fscript, specifically FScriptAnywhere which will let you determine the class and much other information about any visual element of any Cocoa program (and do a lot of other interesting things with Cocoa programs).
In addition to what toholio said, an easy way to get the look and feel of the bottom button bar is with BWToolkit.

Resources