AppCode 2022.2 Help

Extract type alias

Type aliases are used to provide alternative names for existing types. With the Extract type alias refactoring, you can easily create new type aliases.

  1. Place the caret at the type you want to extract to an alias and press Ctrl+Alt+Shift+A or select Refactor | Extract/Introduce | Type Alias from the main menu.

  2. If there are several expression to choose from, select one from the list that opens and press :

    Extract type alias
  3. In the dialog that opens, you can specify the a new type alias name or use the name suggested by AppCode:

    the Introduce Type Alias dialog
  4. Select the visibility modifier for the new type alias from the Visibility list.

  5. Click OK.

    If AppCode finds any usages of the extracted code in the current file, it will suggest you to replace them with the type alias reference. In the dialog that opens, click Yes to process the duplicates or No to leave the code as it is.

Code example

Before

After

// (Int) -> Boolean will be extracted fun foo(p: (Int) -> Boolean) = p(42) fun main() { val f: (Int) -> Boolean = { it > 0 } println(foo(f)) val p: (Int) -> Boolean = { it > 0 } println(listOf(1, -2).filter(p)) }
// New type alias added typealias IntToBoolean = (Int) -> Boolean // All the occurrences of (Int) -> Boolean // replaced with IntToBoolean fun foo(p: IntToBoolean) = p(42) fun main() { val f: IntToBoolean = { it > 0 } println(foo(f)) val p: IntToBoolean = { it > 0 } println(listOf(1, -2).filter(p)) }
    Last modified: 12 May 2021