본문 바로가기

FE 공부20

Swift _ Stepper A control for incrementing or decrementing a value. 음량 버튼으로 소리를 조정하는 것처럼 + - 를 통해 값 증감을 컨트롤 By default, pressing and holding a stepper’s button increments or decrements the stepper’s value repeatedly. The rate of change depends on how long the user continues pressing the control. To turn off this behavior, set the autorepeat property to false. : 버튼을 누르거나 꾹 누르고 있으면 값이 변함. 오래 누르면 값이 계속 커지거나 작아지는데 .. 2022. 11. 15.
Swift _ Switch button A control that offers a binary choice, such as on/off. _ Apple Developer Documentation on/off와 같은 2개의 반대되는 성질(Boolean)을 선택할 수 있도록 제공되는 버튼 switch 버튼은 아래 사진과 같이 object library(cmd + shift + L)에서 꺼내 쓰면 된다. 위 사진과 같은 형태의 스위치를 토글(toggle)이라고도 한다. on / off 상태 설정을 하려면, isOn _ Apple Developer Documentation Instance Property A Boolean value that determines whether the switch is in the on or off position. T.. 2022. 11. 15.
Swift _ Generics - 형식에 의존하지 않는 범용 코드를 작성할 수 있음 - 코드의 재사용성과 유지 보수의 편의성이 높아짐 func name(parameters) -> Type { code } //Type parameter는 문맥에 따라 실제 형식으로 대체되는 placeholder //예제 func swapInteger(lhs: inout Int, rhs: inout Int) { let tmp = lhs lhs = rhs rhs = tmp } var a = 10 var b = 20 swapInteger(lhs: &a, rhs: &b) a b // Int가 아닌 다른 형식을 교차하는 함수가 필요하면 아래처럼 하나씩 구현해야함 //하지만 함수가 중복됨 func swapInteger16(lhs: inout Int16, rhs: .. 2022. 10. 11.
Swift _ Protocols 형식에서 공통적으로 제공하는 멤버 목록 형식에서 구현해야하는 멤버가 선언되어있음(실제구현은 프로토콜에 포함 X) 구현은 구조체나 Class가 함 -> 프로토콜을 따른다, 프로토콜을 채용한다. 프로토콜에 선언된 멤버를 요구사항이라고 부르기도 함 protocol ProtocolName{ propertyRequirments methodRequirments initializerRequirements subscriptRequirements } //상속 지원, 다중 상속도 허용 protocol ProtocolName: Protocol, ... { } //예제 protocol Something{ func doSomething(){ } } //프로토콜 채용 문법 struct TypeName: ProtocolName, .. 2022. 10. 11.