Skip to content

Instantly share code, notes, and snippets.

View MoathOthman's full-sized avatar
🎯
Focusing

Moath othman MoathOthman

🎯
Focusing
View GitHub Profile
@MoathOthman
MoathOthman / gist:d7adae3bc8d79699556ec74936175d43
Created December 4, 2016 09:44
Objectmapper Transform Dictionary to Array of dictionary of the same type
struct DictionaryToArrayTransform<T: Mappable>: TransformType {
init() {}
func transformFromJSON(_ value: Any?) -> [T]? {
guard let object = value as? [String: Any] else {
return nil
}
if let mapped = T(JSON: object) {
return [mapped]
} else {
return []
@MoathOthman
MoathOthman / onviewdidload
Created March 11, 2018 15:34
On View did load (when u need to execute some code after view is loaded in uiviewcontroller)
class SuperViewController: UIViewController {
typealias VoidClosure = () -> Void
private var onViewDidLoad: [VoidClosure] = []
// public
func addOnViewdidLoad(block: @escaping VoidClosure) {
if isViewLoaded {
block()
} else {
self.onViewDidLoad.append(block)
@MoathOthman
MoathOthman / with uiview
Created January 13, 2019 12:00
for the lazy people
let view = UIView().with {$0.backgroundColor = .red}.with({$0.alpha = 0.3})
extension UIView {
func with(_ process: (UIView) -> ()) -> UIView {
process(self)
return self
}
}