문자열과 문자 (Strings and Characters) - 빈 문자열 초기화 (Initializing an Empty String)

00yhsp·2024년 4월 2일

긴 문자열을 만들기 위한 시작점으로 빈 String 값을 만드려면 빈 문자열 리터럴을 변수에 할당하거나 초기화 구문으로 새 String 인스턴스를 초기화한다.

var emptyString = ""               // empty string literal
var anotherEmptyString = String()  // initializer syntax
// these two strings are both empty, and are equivalent to each other

String 값은 부울 isEmpty 프로퍼티로 비어있는지 체크할 수 있다.

if emptyString.isEmpty {
    print("Nothing to see here")
}
// Prints "Nothing to see here"
profile
iOS Dev

0개의 댓글