Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
p-x9 committed Jun 30, 2023
1 parent ed74378 commit 37195cf
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,85 @@ For example, the `ViewController` can also be referenced as a `VC` by writing th
class ViewContoroller: UIViewController {
/* --- */
}

/* ↓↓↓↓↓ */

print(ViewContoroller.self) // => "ViewController"
print(VC.self) // => "ViewController"
```

### Variable
You can define an alias for a variable as follows
```swift
class SomeClass {
@Alias("title")
var text: String
var text: String = "hello"
}

/* ↓↓↓↓↓ */

let someClass = SomeClass()

print(text) // => "hello"
print(title) // => "hello"
```

### Function/Method
You can define an alias for a function as follows.
In this way, you can call both `hello("aaa", Date())` and `こんにちは("aaa", Date())`.
In this way, you can call both `hello("aaa", at: Date())` and `こんにちは("aaa", at: Date())`.
```swift
class SomeClass {
@Alias("こんにちは")
func hello(_ text: String, at date: Date) {
/* --- */
print(text)
}
}

/* ↓↓↓↓↓ */

let someClass = SomeClass()

someClass.hello("aaa", at: Date()) // => "aaa"
someClass.こんにちは("aaa", at: Date()) // => "aaa"
```

#### Customize Argument Label
Argument labels can also be customized by separating them with ":".

```swift
class SomeClass {
@Alias("こんにちは:いつ")
func hello(_ text: String, at date: Date) {
/* --- */
print(text)
}

@Alias("こんにちは2:_") // Omit argument labels
func hello2(_ text: String, at date: Date) {
/* --- */
print(text)
}

@Alias("こんにちは3::宛") // The first argument label is inherited. The second is customized
func hello3(_ text: String, at date: Date, to: String) {
/* --- */
print(text)
}
}

/* ↓↓↓↓↓ */

let someClass = SomeClass()

someClass.hello("aaa", at: Date()) // => "aaa"
someClass.こんにちは("aaa", いつ: Date()) // => "aaa"

someClass.hello2("aaa", at: Date()) // => "aaa"
someClass.こんにちは2("aaa", Date()) // => "aaa"

someClass.hello3("aaa", at: Date(), to: "you") // => "aaa"
someClass.こんにちは3("aaa", at: Date(), : "あなた") // => "aaa"
```

### Multiple Aliases
Expand Down

0 comments on commit 37195cf

Please sign in to comment.