To run the example project, clone the repo, and run pod install
from the Example directory first.
// UIColor
view.backgroundColor = .oh.hex(0xFFFFFF)
view.backgroundColor = .oh.random
// UITableView
tableView.oh.register(UITableViewCell.self)
// ...
let cell = tableView.oh.dequeue(UITableViewCell.self)
// UserDefaultsWrapper
import OhSwift
@UserDefaultsWrapper("oh.swift.toggle", defaultValue: true)
var toggle: Bool!
// UserDefaults.standard.bool(forKey: "oh.swift.toggle")
"toggle \(toggle!)"
// UserDefaults.standard.set(false, forKey: "oh.swift.toggle")
// UserDefaults.standard.synchronize()
toggle = false
// CodableDefaultWrapper
struct Model: Codable {
@Default<String> var text: String
@Default<Int> var integer: Int
@Default<Double> var decimal: Double
@Default.True var flag: Bool
}
// ...
let jsonString = """
{
"text1": "hello world!",
"integer": 99,
"decimal": 66
}
"""
do {
let model = try JSONDecoder().decode(Model.self, from: jsonString.data(using: .utf8)!)
print(model) // text = "", integer = 99, decimal = 66.0, flag = true
} catch {
print(error.localizedDescription)
}
let testView = UIView.oh.new { make in
make.background(color: .white)
.border(width: 10)
.corner(radius: 20)
if #available(iOS 11.0, *) {
make.corner(radius: 20, corners: [.topLeft, .bottomRight])
}
make.rawValue.frame = .init(x: 50, y: 650, width: 100, height: 100)
}
UIButton(frame: .init(x: 310, y: 650, width: 100, height: 100))
.oh.modifier
.superView(view)
.title("Button")
.titleColor(.oh.random)
.font(ofSize: 20, weight: .semibold)
.action(for: .touchDown) {
print("...")
}
/// disposeBag
button.rx.tap
.subscribe()
.disposed(by: rx.disposeBag)
/// ็ฎๅ items(cellIdentifier:,cellType:)
/// ๅฏ้
ๅ tableView.oh.register(UITableViewCell.self) ไฝฟ็จ
Observable.just(dataSource.map { $0.items }.flatMap { $0 } )
.bind(to: tableView.rx.items(cell: UITableViewCell.self)) { (row, element, cell) in
cell.textLabel?.text = element
}
.disposed(by: rx.disposeBag)
/// ๅจๅ modelSelected ๅบ็กไธ่ฟๅ IndexPath
tableView.rx.modelSelectedAtIndexPath(String.self)
.subscribe(onNext: { (element, indexPath) in
print("\(element) \(indexPath)")
})
.disposed(by: rx.disposeBag)
Oh.Swift is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Oh.Swift'
# Install RxSwift extension
pod 'Oh.Swift/Rx'
Starkrimson, [email protected]
Oh.Swift is available under the MIT license. See the LICENSE file for more info.