Xcode 6.4: You should be able to set the tag of a custom NSView in Interface Builder

Originator:aralbalkan
Number:rdar://21888110 Date Originated:18-Jul-2015 05:48 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.4 (6E35b)
Classification:Enhancement Reproducible:Always
 
Summary:

You cannot set the tag of a custom NSView in Interface Builder. This is a pain :) (Especially now that more people will be using them thanks to @IBDesignable and @IBInspectable support)

Steps to Reproduce:

1. Create a custom NSView 
2. Try to set its tag via the Attributes Inspector

Expected Results:

It just works, like with any other NSView.

Actual Results:

It doesn’t work — the option is greyed out.

Workaround:

I actually had to do this :)

extension NSView
{
    func viewWithCustomTag(customTag:Int) -> NSView?
    {
        //
        // Iterates over subviews and returns the view with the specified custom tag.
        // The custom view must implement the CustomTaggable protocol.
        //
        // (Why we can’t use regular tags in custom NSViews is beyond me.)
        //
        for view in subviews
        {
            if let view = view as? NSView, customTaggableView = view as? CustomTaggable
            {
                if customTaggableView.customTag == customTag
                {
                    return view
                }
            }
        }
        return nil
    }
}

protocol CustomTaggable
{
    var customTag:Int {get set}
}


@IBDesignable
class MyView: NSView, CustomTaggable
{
    
    @IBInspectable var customTag:Int = -1

    // …

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!