Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a key combination in Xcode to implement a Protocol?

In Visual Studio if I define a class to implement an interface e.g.

class MyObject : ISerializable {}

I am able to right click on ISerializable, select "Implement Interface" from the context menu and see the appropriate methods appear in my class definition.

class MyObject : ISerializable {
    #region ISerializable Members
    public void GetObjectData(SerializationInfo info, 
                StreamingContext context)
    {
        throw new NotImplementedException();
    }
    #endregion
}

Is there anything anything like this functionality available in Xcode on the Mac? I would like to be able to automatically implement Protocols in this way. Maybe with the optional methods generated but commented out.

like image 994
AidenMontgomery Avatar asked Oct 11 '08 16:10

AidenMontgomery


3 Answers

XCode currently does not support that kind of automation. But: an easy way to get your code bootstrapped with a protocol is to option-click the protocol name in your class declaration

@interface FooAppDelegate : NSObject <NSApplicationDelegate, 
                                      NSTableViewDelegate> {

to quickly open the .h file defining the protocol. From there, copy and paste the methods you're interested in. Those headers tend to be well-commented, which helps in determining which methods you can safely ignore.

like image 159
Clay Avatar answered Nov 18 '22 13:11

Clay


I have not seen that feature in Xcode. But it seems like someone could write a new user script called "Place Implementor Defs on Clipboard" that sits inside of Scripts > Code.

You did not find this useful.

like image 6
David Grant Avatar answered Nov 18 '22 14:11

David Grant


There is not currently such a refactoring in Xcode.

If you'd like it, please file an enhancement request.

like image 5
Chris Hanson Avatar answered Nov 18 '22 13:11

Chris Hanson