목록전체 글 (109)
大器晩成
스위프트에서 프로토콜은 일급객체이기 때문에, 타입으로 사용할 수 있습니다. * 프로토콜은 타입입니다.protocol Bird { func fly() func sit()}struct Eagle: Bird { func fly() { print("독수리가 날고있습니다.") } func sit() { print("독수리가 앉아있습니다.") } func hunt() { print("독수리가 사냥 중입니다.") } }struct Sparrow: Bird { func fly() { print("참새가 날고있습니다.") } func sit() { print("참새가 앉아있..
[서브스크립트 요구사항]get, set 키워드를 통해 읽기/쓰기 여부를 설정 (최소한의 요구사항)get 키워드 -> 최소한 읽기 서브스크립트로 구현 / 읽기, 쓰기 모두 구현 가능합니다.get/set 키워드 -> 반드시 읽기, 쓰기 모두 구현해야 합니다.protocol Numbers { subscript(idx: Int) -> Int { get }}struct Number: Numbers { // subscript(idx: Int) -> Int {// get {// return 0// }// } subscript(idx: Int) -> Int { get { return 0 } set..
iOS에서 지원해 주는 MapKit을 활용하여 특정 좌표에 Pin을 보여주는 예제입니다. import UIKitimport MapKitclass ViewController: UIViewController { private let mapView = MKMapView() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white layout() } private func layout() { view.addSubview(mapView) // Auto Resizng 해제 mapView..
CollectionView 마지막 3탄으로 동적으로 셀의 크기를 개별적으로 변경하는 방법에 대해서 알아보려고 합니다. 이번에 동적으로 셀의 크기를 변경하는 방법은 아래 영상처럼 레이블에 크기에 따른 셀의 크기를 조절해보려고 합니다. 1. 컬렉션 셀의 크기를 개별로 설정하는 방법extension ViewController: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { ..