AppCode 2016.3 Help

Creating Code Constructs Using Generate Menu

The Generate menu helps you quickly create standard code constructs in your code. Depending on the current context, the caret position, or selected code, AppCode gives you a list of constructs to be generated.

Depending on a language, the Generate menu provides the following features:

Generate method/function
  • Create -initWith and -init/encodeWithCodermethods.
  • Create -copyWith method.
  • Create -isEqual:and -hash methods.
  • Create -description method.
  • Create +instance method.
  • Declare and synthesize properties.
  • Declare members in header file.
Not supported
  • Constructors and destructors.
  • Getters and setters.
Implement method/function/member Supported. Supported. Supported.
Override method/function/member Supported. Supported. Supported.

In unit tests, you can create setUp/tearDown methods or test methods for OCUnit, XCTest, or Google Test. It, context, beforeEach, afterEach and specify blocks can be created for Kiwi.


Examples below demonstrate how Generate | Override command works for Objective-C and Swift:


@protocol MyProtocol @optional -(void)bar; @end @interface MyObject: NSObject <MyProtocol> -(void)foo; @end @implementation MyObject -(void) foo { } @end
@protocol MyProtocol @interface MyObject: NSObject <MyProtocol> -(void)foo; -(void)bar; @end @implementation MyObject -(void) foo { } - (void)bar { } @end


class Base { func foo(x: Int) -> String { return "" } } class Impl: Base { }
class Base { func foo(x: Int) -> String { return "" } } class Impl: Base { override func foo(x: Int) -> String { return } }

To create code constructs using the Generate menu

  1. Open the file where you are going to generate code and place the caret at the corresponding position, e.g. in the implementation of a class.
  2. Do one of the following:
    • On the main menu, choose Code | Generate.
    • Right-click the editor and choose Generate on the context menu.
    • Press N/A.
  3. In the Generate menu that is displayed in the editor, select the desired construct.

    Depending on the selected item, AppCode either inserts the construct immediately or shows a dialog for additional input.

    Dialog examples

    In Overrides/Implement dialog, choose method/member to be implemented (or overrode) and click OK to proceed.

    Refer to Implement/Override dialog reference for more details.

See Also

Last modified: 6 December 2016