> For the complete documentation index, see [llms.txt](https://krjaeh0.gitbook.io/j-log/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krjaeh0.gitbook.io/j-log/programming/languages/swift-and-ios/singleexpression.md).

# SingleExpression

{% hint style="info" %}
하나의 표현식으로 이뤄진 구문입니다.\
종종 함수나 클로저의 반환값으로 직접 사용될 수 있습니다.\
Swift 언어의 클로저 본문이 단일 표현식으로만 구성되어 있을 때 `return` 키워드를 생략할 수 있습니다.\
코드의 표현력을 강화하고, 간결하게 작성할 수 있도록 도와줍니다.
{% endhint %}

### 예제

```swift
/* // 축약 전 클로저
 * let add: (Int, Int) -> Int = { (a, b) in
 *     return a + b
 * }
 */
 
// 축약 후 클로저
let add: (Int, Int) -> Int = { $0 + $1 }
print(add(3, 4))
```

### 이점

* 코드의 간결성과 명확성을 높일 수 있다.
* 특히 함수나 클로저가 단순한 연산만 수행할 때, 코드를 간결하게 만들어 가독성을 향상시킬 수 있다.

### 활용

* 단일 표현식은 단순 계산, 조건문 평가, 또는 값의 반환 등 다양한 곳에 활용될 수 있다.
* 조건부 연산자는 종종 단일 표현식으로 사용되어 간단한 조건에 따라 다른 값을 반환할 때 유용하다.

```swift
let result = (x > y) ? x : y
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://krjaeh0.gitbook.io/j-log/programming/languages/swift-and-ios/singleexpression.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
