Programming Language
-
[Swift] Hashable 프로토콜Programming Language/Swift 2022. 7. 1. 16:42
개발하다보면 Hashable 프로토콜을 정말 많이 사용하게 된다. Hashable과 옵셔널 값을 같이 사용하면서 생긴 궁금증도 있고, Hashable을 굉장히 많이 사용하지만 깊이 알고 있지 않은 상태로 사용하고 있는 것 같아 Hashable 이 어떤 프로토콜인지 좀 더 자세히 공부해보려고 한다. Hashing Hasing(해싱)은 주어진 key나 문자열을 다른 값으로 변환시키는 작업이다. 해싱을 통해 고정 길이의 더 짧은 key, value로 표현되고, 이 key-value를 사용해서 원래의 값을 더 쉽고 빠르게 찾을 수 있다. 해싱은 데이터를 특정 정수 값으로 매핑하는 함수, 알고리즘을 사용한다. 즉 hash function을 사용해서 데이터에서 새로운 값을 만드는 것이다. 이 새로운 값을 hash ..
-
[Swift] 22. Generics - 제네릭Programming Language/Swift 2022. 6. 19. 09:14
Generics — The Swift Programming Language (Swift 5.7) Generics Generic code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements that you define. You can write code that avoids duplication and expresses its intent in a clear, abstracted manner. Gener docs.swift.org Generic 코드는 어떤 타입에도 유연하게 대응할 수 있는 재사용 가능한 함수, 타입을 작성할 수 있게 해준다. 깔끔하고 추상화..
-
[Swift] 21. Extension - 익스텐션Programming Language/Swift 2022. 6. 19. 09:11
Extensions — The Swift Programming Language (Swift 5.7) Extensions Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you don’t have access to the original source code (known as retroactive modeling). Extensions docs.swift.org Extension은 클래스, 구조체, 열거형, 프로토콜에 새로운 기능을 추가한다. 원래 소스 코드에 접근할 수 없을 때 타입을 확장..
-
[Swift] 20. Protocol - 프로토콜Programming Language/Swift 2022. 6. 12. 09:51
Type Casting — The Swift Programming Language (Swift 5.7) Type Casting Type casting is a way to check the type of an instance, or to treat that instance as a different superclass or subclass from somewhere else in its own class hierarchy. Type casting in Swift is implemented with the is and as operators. These tw docs.swift.org Protocol은 특정 기능을 할 수 있는 메서드, 프로퍼티, 요구사항의 청사진을 정의한다. 이 요구사항을 실제로 구현하기..
-
[Swift] 19. Type Casting - 타입 캐스팅Programming Language/Swift 2022. 6. 12. 09:44
Type Casting — The Swift Programming Language (Swift 5.7) Type Casting Type casting is a way to check the type of an instance, or to treat that instance as a different superclass or subclass from somewhere else in its own class hierarchy. Type casting in Swift is implemented with the is and as operators. These tw docs.swift.org 타입 캐스팅은 인스턴스의 타입을 확인하거나 다른 클래스의 인스턴스로서 다루기 위한 방법이다. Swift에서의 타입 캐스팅은..
-
[Swift] 18. Inheritance - 상속Programming Language/Swift 2022. 6. 12. 09:41
Swift에서의 상속은 클래스를 다른 타입과 구분짓는 근복적인 행위다. 상속에 대해 알아보자. Inheritance — The Swift Programming Language (Swift 5.7) Inheritance A class can inherit methods, properties, and other characteristics from another class. When one class inherits from another, the inheriting class is known as a subclass, and the class it inherits from is known as its superclass. Inheritance is docs.swift.org 클래스는 다른 클래스에서 메서드..
-
[Swift] 17. Subscript - 서브스크립트Programming Language/Swift 2022. 6. 12. 09:31
Swift에서 타입의 기능을 확장(extend)하는 방법은 많다. 기능, 속성을 물려받아 수직 확장할 수 있는 상속, 타입에 기능을 추가해 수평적으로 확장할 수 있는 익스텐션도 있다. 다양한 확장 기법을 통해 타입을 더욱 유용하게 사용할 수 있게 하는 방법을 알아보자. Subscripts — The Swift Programming Language (Swift 5.7) Subscripts Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence. You use subscripts to set and..
-
[Swift] 16. Monad - 모나드Programming Language/Swift 2022. 6. 5. 09:12
모나드 개념에 대해 알아보자. 모나드는 함수형 프로그래밍 패러다임에서 등장하는 용어다. 함수형 프로그래밍에서, monad는 프로그램 요소 (function)들을 조합하고 그들의 리턴 값을 추가적인 연산을 통해 감싸는 구조의 소프트웨어 디자인 패턴이다. 무슨 말인지 이해하기 어려운데, 모나드를 이해하기 위해서는 값을 어딘가에 포장한다는 개념을 이해하는 것에서 출발한다. Swift에서 모나드를 사용한 예 하나는 옵셔널이다. 옵셔널은 값이 있을지, 없을지 모르는 상태를 포장한 것이다. 모나드는 순서가 있는 연산을 처리할 때 사용되는 디자인 패턴으로 부작용을 관리하기 위해 함수형 프로그래밍 언어에서 사용된다. 모나드를 깊게 판다면 끝도 없이 복잡해지고, 모나드를 설명하는 글들도 제각기 모나드가 무엇인지 설명하는..