Skip to content

Instantly share code, notes, and snippets.

View gaeng2y's full-sized avatar
🦖
Mai Paura

Kyeongmo Yang gaeng2y

🦖
Mai Paura
View GitHub Profile
@gaeng2y
gaeng2y / classInit.swift
Created April 26, 2022 04:48
class example
class User {
var nickname: String
var age: Int
init(nickname: String, age: Int) {
// init
self.nickname = nickname
self.age = age
}
@gaeng2y
gaeng2y / protocol.swift
Created April 26, 2022 04:52
protocol example
protocol name {
// body
}
@gaeng2y
gaeng2y / extension.swift
Created April 26, 2022 04:53
extension
extension name {
// addition
}
enum Student {
case Name(String)
case Mark(Int,Int,Int)
}
var studDetails = Student.Name("Swift")
var studMarks = Student.Mark(98,97,95)
switch studMarks {
case .Name(let studName):
print("Student name is: \(studName).")
case .Mark(let Mark1, let Mark2, let Mark3):
@gaeng2y
gaeng2y / doCatch.swift
Created April 26, 2022 04:56
do-catch
do {
try 표현식 결과
} catch 패턴 1 {
처리 결과
} catch 패턴 2 where 조건 {
처리 결과
} catch {
처리 결과
}
enum PhoneError: Error { case unknown case batteryLow(batteryLevel: Int) }
throw PhoneError.batteryLow(batteryLevel: 20)
- 던져진 오류를 처리하기 위한 작업이 필요하다
```swift
func checkPhoneBatteryStatus(batteryLevel: Int) throws -> String {
guard batteryLevel != -1 else { throw PhoneError.unknown }
guard batteryLevel > 20 else { throw PhoneError.batteryLow(batteryLevel: batteryLevel) }
return "배터리 상태 정상"
}
{ (param) -> return type in
// body
}
@gaeng2y
gaeng2y / AppDelegate.m
Last active April 26, 2022 05:04
issue
if (@available(iOS 15.0, *)) {
[[UITableView appearance] setSectionHeaderTopPadding:0.0f];
} else {
// Fallback on earlier versions
}
@gaeng2y
gaeng2y / CustomInputView.swift
Created April 26, 2022 05:14
custom inpurt view
import UIKit
class CustomInputView: UIInputView {
override init(frame: CGRect, inputViewStyle: UIInputView.Style) {
super.init(frame: frame, inputViewStyle: inputViewStyle)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
import UIKit
class ViewController: UIViewController {
lazy var textField: UITextField = UITextField()
lazy var label: UILabel = UILabel()
lazy var btn: UIButton = UIButton()
lazy var safeArea = view.safeAreaLayoutGuide
lazy var isCustomInputView = false
override func viewDidLoad() {