Install via Carthage
github "atsushi130/SwiftExtensions"
- Swift 4 or later
- NSObject
- Int
- Double
- CGFloat
- String
- Bool
- Dictionary
- Array
- Date
- DateFormatter
- CGColor
- UIColor
- UITextView
- UICollectionView
- UITableView
- UIView
- UUID
- NibDesignable
- NibInstantiatable
- CaseIterable
Get class name.
let view = CustomView()
print(view.className)Half
let number = 3
print(number.half) // 1.5Half
let number = 3.0
print(number.half) 1.5Floor
let number = 1.4
print(number.floor) // 1.0Ceil
let number = 1.4
print(number.ceil) // 2.0Round
let number = 1.5
print(number.round) // 2.0CGFloat
let number = 1.5.cgFloatThe same as String extensions.
attributed
"string".attributedtoDate
"2018/01/01 00:00:00".toDate()Regular expression
password.isMatch(pattern: "^(?=.*[a-z])(?=.*[$@$#!%*?&])[A-Za-z\\d$@$#!%*?&]{8,}$")toInt
print(true.toInt) // 1operator +
["key1": "value1"] + ["key2": "value2"] // ["key1": "value1", "key2": "vaule2"]Nullable element
let array = [1, 2, 3]
array[ifAny: 4] // .nonetoString
let dateString = Date().toString()let formatter = DateFormatter.from(locale: Local.current, format: "yyyy/MM/dd HH:mm:ss")to UIColor
view.backgroundColor = cgColor.uiColorlet color = UIColor.hex(hex: 0xAABBCC)
let color = UIColor.hex(hexString: "ffffff")let textView = UITextView()
textview.placeholder = "Input message"Custom cell registration.
@IBOutlet private weak var collectionView: UICollectionView! {
didSet {
self.layout = UICollectionViewFlowLayout()
self.collectionView.collectionViewLayout = self.layout
self.collectionView.register(cellType: CustomCell.self)
self.collectionView.register(reusableViewType: CustomReusableView.self)
self.collectionView.dataSource = self
self.collectionView.delegate = self
}
}Other example.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return collectionView.dequeueReusableCell(with: CustomCell.self, for: indexPath)
}safeAreaInsets
// ios10.x or less: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
let safeAreaInsets = self.view.safeAreaInsetsfillSuperview
let view = UIView()
superView.addSubView(view)
view.fillSuperview()UUID.generate()Setup the File’s Owner with the custom class you created.

conform to NibDesignable. Please call configureNib method on init(frame:) and init?(decoder:).
@IBDesignable
final class ReactiveView: UIView, NibDesignable {
init(frame: CGRect) {
super.init(frame: frame)
self.configureNib()
}
required init?(decoder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.configureNib()
}
}Last step, set its class as custom view (ex: ReactiveView) in storyboard.

final class CustomView: NibInstantiatable { ... }
let customView = CustomView.instantiate() // create instance from CustomView.Xibenum License: CaseIterable {
case free
case enterprise
}
print(License.allCases) // [License.free, License.enterprise]SwiftExtensions is available under the MIT license. See the LICENSE file.
