countElements
[Swift] String 타입에 length 메소드가 없는 이유
Swift의 String 타입에는 length 프로퍼티나 메소드가 없다. 이상하게 들리겠지만 실제로 그렇다. Swift에서 문자열의 길이를 구하려면 이럼 메소드 대신에 countElements(_:)라는 글로벌 함수를 사용해야 한다. 더군다나 이 countElements(_:) 함수는 문자열을 처음부터 순회(iterate)하기 때문에 매우 긴 문자열을 다룰 때라면 주의해야 한다. NSString도 length 프로퍼티를 제공하는데 왜 Swift의 문자열 타입은 길이