본문 바로가기

IOS 개발

[iOS] Self Expression

Self 표현식

Self Expression

 

self 표현식은 현재 유형 또는 해당 유형의 인스턴스에 대한 명시적 참조입니다. 다음과 같은 형식이 있습니다.

The self expression is an explicit reference to the current type or instance of the type in which it occurs. It has the following forms:

 

self

 

self.member name

 

self[subscript index]

 

self(initializer arguments)

 

self.init(initializer arguments)

 

 

이니셜 라이저, 아래 첨자 또는 인스턴스 메서드에서 self는 현재 발생하는 형식의 현재 인스턴스를 나타냅니다. 유형 방법에서 self는 현재 발생하는 유형을 나타냅니다.

In an initializer, subscript, or instance method, self refers to the current instance of the type in which it occurs. In a type method, self refers to the current type in which it occurs.

 

 

자체 표현식은 멤버에 액세스 할 때 범위를 지정하는 데 사용되며, 범위에 동일한 이름의 다른 변수 (예 : 함수 매개 변수)가있을 때 명확성을 제공합니다. 예를 들면 다음과 같습니다.

The self expression is used to specify scope when accessing members, providing disambiguation when there is another variable of the same name in scope, such as a function parameter. For example:

 

값 유형의 변경 방법에서 해당 값 유형의 새 인스턴스를 self에 할당 할 수 있습니다. 예를 들면 다음과 같습니다.

In a mutating method of a value type, you can assign a new instance of that value type to self. For example:

 

GRAMMAR OF A SELF EXPRESSION

self-expression  self | self-method-expression| self-subscript-expression | self - initalizer-expression

self-method-expression  self . identifier

self-subscript-expression  self [ function-call-argument-list ]

self-initializer-expression  self . init

 

 

 

 

 

 

 참조 : 애플공식문서 the swift programming language

'IOS 개발' 카테고리의 다른 글

[iOS] NSPredicate  (0) 2020.01.30
[iOS] ?? (_:_:) Generic Operator_nil-coalescing [일반 연산자 _ 무- 응집]  (0) 2020.01.22
[iOS] Keyword 간단 요약  (0) 2020.01.20
[iOS] Self  (0) 2020.01.20
[iOS] DateFormatter  (0) 2020.01.20