[4주 - 1일차] 학습 정리

okstring·2020년 11월 23일
0

codesquad-cocoa

목록 보기
16/25

Date

reference

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "hh:mm:ssa"
let date = dateFormatter.date(from: dateAsString)
print(date)

dateFormatter.dateFormat = "HH:mm:ss"
if let bindingDate = date {
    print(dateFormatter.string(from: bindingDate))
}

NSCalender - 현재 시간 구하기

let date = Date()
let calendar = NSCalendar.current

let month = calendar.component(.month, from: date)
let day = calendar.component(.day, from: date)

let hour = calendar.component(.hour, from: date)
let minutes = calendar.component(.minute, from: date)
let seconds = calendar.component(.second, from: date)
print("\(month), \(day)hours = \(hour):\(minutes):\(seconds)")

UIView.transition

// 해당 label 크기가 늘었다가 줄어드는 transition
UIView.transition(with: seconds, duration: 0.5, options: .transitionCrossDissolve, animations: {
    self.seconds.font = self.seconds.font.withSize(25)
}) { isFinished in
    UIView.transition(with: self.seconds, duration: 0.5, options: .transitionCrossDissolve, animations: {
        self.seconds.font = self.seconds.font.withSize(20)
    })
}

enum, switch 활용

enum TimeType {
    case DayOrNight(Int)
    case Hour(Int)
    case Minute(Int)
    case Second(Int)
    case none
}

var classifiedTag: TimeType {
    get {
        switch rawTag / 100 {
        case 1: return TimeType.DayOrNight(rawTag % 100)
        case 2: return TimeType.Hour(rawTag % 100)
        case 3: return TimeType.Minute(rawTag % 100)
        case 4: return TimeType.Second(rawTag % 100)
        default: return TimeType.none
        }
    }
}

func isThisLableCurrentTime(_ tag: Int) -> Bool {
    rawTag = tag
    currntTime()

    switch classifiedTag {
    case .DayOrNight(let value): return isDayOrNightNow(value)
    case .Hour(let value): return isCorrectHour(value)
    case .Minute(let value): return isCorrectMinute(value)
    default: break
    }
    return false
}
profile
step by step

0개의 댓글