새로 알아간 것들
String - NSString을 사용해 Int로 변환
String(format: "%.\(total)d", (String(3, radix: 2) as NSString).integerValue)
String - init(_:radix:)
extension
extension String {
func digitMatching(count: Int) -> String {
if self.count < count {
return String(repeating: "0", count: count - self.count) + self
}
return self
}
}
Set variable to the Bool
var comparator: (Int, Int) -> Bool = (<)
- Label color 설정과는 모양이 약간 다르다
entranceButton.setTitleColor(waitProcess.entranceButtonColor, for: .normal)
progressBar - 속성 설정 방법
progressBar.setProgress(Float(waitProcess.currentGuestCount) * (1 / 20) , animated: false)
Bubble Sort
class BubbleSort {
private var array = Array<Int>()
private var result = Array<Int>()
init(of array: Array<Int>) {
self.array = array
self.result = array
}
func sorted(isAscending: Bool) -> Array<Int> {
var swapped: Bool
var temp = 0, swapCounter = 0
var comparator: (Int, Int) -> Bool = (>)
if !isAscending { comparator = (<) }
func swap(aIndex: Int, bIndex: Int) {
temp = self.result[aIndex]
self.result[aIndex] = self.result[bIndex]
self.result[bIndex] = temp
}
repeat {
swapped = false
for i in 0..<result.count - swapCounter - 1 {
if comparator(self.result[i], self.result[i + 1]) {
swapped = true
swap(aIndex: i, bIndex: i + 1)
}
}
swapCounter += 1
} while swapped
return result
}
}