Skip to content

Instantly share code, notes, and snippets.

var isLike = false
if isLike {
fetchDisLikeAPI()
} else {
fetchLikeAPI()
}
isLike = !isLike
class MyCalss {
var resultHandler: CompletionClosure = nil
}
class MyCalss {
var resultHandler: CompletionClosure
}
typealias CompletionClosure = (() -> ())?
extension UITextView {
func removeTextPadding() {
textContainer.lineFragmentPadding = 0
textContainerInset = .zero
}
}
// 移除上下的間距
textView.textContainerInset = .zero
// 移除左右的間距
textView.textContainer.lineFragmentPadding = 0
@daoseng33
daoseng33 / textFieldMaxLength.swift
Created September 19, 2018 09:25
Let you set UITextField max length in storyboard or xib
// Set textfield max length
private var __maxLengths = [UITextField: Int]()
extension UITextField {
@IBInspectable var maxLength: Int {
get {
guard let l = __maxLengths[self] else {
return Int.max // (global default-limit. or just, Int.max)
}
return l
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if isBeingPresented {
// start timer
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
enum SectionTypes: CaseIterable {
case header
case list
}
print(SectionTypes.allCases.count) // 2
enum SectionType: Int {
case header = 0
case list
static let count: Int = {
var max: Int = 0
while let _ = SectionType(rawValue: max) { max += 1 }
return max
}()
}