Skip to content

Instantly share code, notes, and snippets.

View ksmandersen's full-sized avatar
🏠
Working from home

Kristian Andersen ksmandersen

🏠
Working from home
View GitHub Profile
@ksmandersen
ksmandersen / part-1
Created May 17, 2016 07:12
Eliminating boilerplate code with Generic’s in Swift
class MyAwesomeViewConroller: UIViewController {
var awesomeView: MyAwesomeView {
return view as MyAwesomeView
}
init() {
super.init(nibName: nil, bundle: nil)
}
override func loadView() {
@ksmandersen
ksmandersen / generic_view.swift
Created May 26, 2016 19:54
Good Swift, Bad Swift - Part 1
public class View: UIView {
public init() {
super.init(frame: CGRect.zero)
configureView()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
configureView()
}
class AwesomeView: GenericView {
let bestTitleLabel: UILabel = {
let label = UILabel()
label.textAlignment = .Center
label.textColor = .purpleColor()
return label
}()
let otherTitleLabel: UILabel = {
@ksmandersen
ksmandersen / guard.swift
Last active June 19, 2016 09:08
Good Swift, Bad Swift - Part 2
@objc func didPressLogIn(sender: AnyObject?) {
guard !isPerformingLogIn else { return }
isPerformingLogIn = true
let email = contentView.formView.emailField.text
let password = contentView.formView.passwordField.text
guard validateAndShowError(email, password: password) else {
isPerformingLogIn = false
return
currentRequest?.getValue { [weak self] result in
guard let user = result.okValue where result.errorValue == nil else {
self?.showRequestError(result.errorValue)
self?.isPerformingSignUp = false
return
}
self?.finishSignUp(user)
}
ImageView img = (ImageView)findViewById(R.id.imgView1);
img.setImageResource(android.R.drawable.ic_media_play);
// This is a generated file, do not edit!
// Generated by R.swift, see https://github.com/mac-cain13/R.swift
import Foundation
import Rswift
import UIKit
/// This `R` struct is code generated, and contains references to static resources.
struct R {
/// This `R.color` struct is generated, and contains static references to 0 color palettes.
import UIKit
import GenericViewKit
public class StateView: GenericView {
public enum State {
case Loading
case Loaded
case Error
}
class AwesomeView: GenericView {
let bestTitleLabel = UILabel().then {
$0.textAlignment = .Center
$0.textColor = .purpleColor()tww
}
let otherTitleLabel = UILabel().then {
$0.textAlignment = .
$0.textColor = .greenColor()
}
import UIKit
import GenericViewKit
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private let applicationController = ApplicationController()
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
applicationController.configureReporting()