String ✅ Array: An ordered, random-access collection. Preinitialized with a fixed number of default values var digitCounts = Array(repeating: 0, count: 10) print(digitCounts) // Prints "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]" Accessing Array Values for in let streets = ["Albemarle", "Brandywine", "Chesapeake"] for street in streets { print("I don't live on \(street).") } // Prints "I don't live on Albem..
RxSwift의 Operator를 배우던 중에 다시 만난 map, filter. 이의 기본이 되는 Swift의 대표적인 고차함수인 map, filter, reduce를 알아보자. 고차함수란? Higher Order Functions 다음 중 하나를 수행하는 함수이다. 하나 이상의 함수를 인수로 취한다. 함수를 결과로 반환한다. Swift의 Function(함수)는 First-Class Citizen(일급객체)이므로 값처럼 인자로 전달할 수도 있고 반환할 수도 있다. 고차함수는 왜 쓰냐고? 데이터의 연산을 쉽게 처리하기 위해서. Swift의 대표적인 고차함수인 map(변형), filter(거름), reduce()를 알아보자. Swift의 Collection Types(Array, Dictionary, Se..
RxSwift를 공부하면서 Closure가 다시 등장했다. 들어본 개념이고, 제대로 파보진 않았어서 겸사겸사 정리. Closure는 Swift의 함수형 프로그래밍 패러다임을 접할 때 꼭 알아야 할 개념 중 하나이다. Closure는 일정 기능을 하는 코드를 하나의 블록으로 모아놓은 것을 의미한다. Swift의 Closure는 C언어나 Objective-C의 blocks 이나 다른 프로그래밍 언어의 lambdas와 비슷하다. (함수와 비슷하다고 볼 수 있는데, 사실 함수는 Closure의 한 형태라고 볼 수 있다.) Closures are self-contained blocks of functionality that can be passed around and used in your code. Closur..
iOS 프로젝트를 진행하면서 정말 수도 없이 봤던 Extension. 처음 사용해본 건 ViewController에 UITableViewDelegate, UITableViewDataSource 프로토콜을 채택할 수 있도록 확장하기 위해서였다. 이 외에도 기본 Type들에 원래 있는 기능은 아니지만, 자주 사용되는 기능들을 모아놓기 위해 사용하기도 했었다. UIView에 그림자를 설정할 수 있도록 하는 메소드를 만들어 두었던 것이 대표적인 예시다. Extension Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend typ..
Q. Swift에서 Structure와 Class의 차이는 무엇이고 언제 써야 하는가? 우선 Structure와 Class는 데이터를 용도에 맞게 묶어서 표현하고자 할 때 사용하는 문법이다. (사용자 정의 Data Type) 이 둘은 Property(프로퍼티 - 값)와 Method(메소드 - 기능)를 가진다. Swift에서 Structure와 Class는 모습과 문법이 거의 흡사하다. 둘의 가장 큰 차이점을 먼저 말하자면, Structure는 값 타입(Value Types)인 반면, Class는 참조 타입(Reference Types)이다. 참고) 일부 프로그래밍 언어에서는 소스 파일 하나 당 하나의 Structure 또는 Class만 선언하고 구현할 수 있지만, Swift에서는 별도의 제약사항이 없다...