Skip to content

Instantly share code, notes, and snippets.

View s4cha's full-sized avatar
🎯
Focusing

Sacha DSO s4cha

🎯
Focusing
View GitHub Profile
@s4cha
s4cha / DogchowBenefitView.kt
Last active September 5, 2018 13:54
Android Custom View Component
package com.octopepper.yummypets.component.dogchow
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import com.octopepper.yummypets.R
import kotlinx.android.synthetic.main.dogchow_benefit.view.*
class DogchowBenefitView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
@s4cha
s4cha / ViewController.swift
Created July 31, 2018 19:19
Typical Stevia/ViewController use case
//
// ViewController.swift
// steviademo
//
// Created by Onur Geneş on 17.07.2018.
// Copyright © 2018 Onur Geneş. All rights reserved.
//
import UIKit
import Stevia
@s4cha
s4cha / View.swift
Created July 31, 2018 19:18
Typical Stevia View
//
// View.swift
// heroandstevia
//
// Created by Sacha on 31/07/2018.
// Copyright © 2018 Onur Geneş. All rights reserved.
//
import UIKit
import Stevia
@s4cha
s4cha / NativeDependencyInversion.swift
Created July 26, 2018 12:22
Native Swift Dependency Inversion
protocol <#Depencency#> {
func foo()
}
protocol Has<#Depencency#> {
func get<#Depencency#> () -> <#Depencency#>
}
// Implementation
public extension Optional where Wrapped == String {
var isEmptyOrNil: Bool { return (self ?? "").isEmpty }
}
@s4cha
s4cha / AsyncExample.swift
Created May 12, 2017 14:57
AsyncExample.swift
// Say you're on the main thread
DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async {
// Do something expensinve in background
var mySuperLongComputedResult = computeSuperLongStuff()
DispatchQueue.main.async {
// come back to the main thread to ping UI
label.text = mySuperLongComputedResult
}
}
tableView.register(MyCell.self, forCellReuseIdentifier: MyCell.reuseIdentifier)
tableView.register(Mycell.self)
extension UITableView {
func register<T: UITableViewCell>(_: T.Type) where T: Reusable {
register(T.self, forCellReuseIdentifier: T.reuseIdentifier)
}
}
extension Reusable {
static var reuseIdentifier: String {
return String(describing: Self.self)
}
}