Skip to content

Instantly share code, notes, and snippets.

View MrAlek's full-sized avatar

Alek Åström MrAlek

View GitHub Profile
import Foundation
import UIKit
enum SafeRawRepresentable<Wrapped: RawRepresentable>: RawRepresentable {
case known(Wrapped)
case unknown(Wrapped.RawValue)
var rawValue: Wrapped.RawValue {
switch self {
@MrAlek
MrAlek / NibWrapperView.swift
Last active January 14, 2016 08:45
@IBDesignable view that wraps & renders views from nib files
//
// NibWrapperView.swift
//
// Created by Alek Åström on 2016-01-13.
// http://github.com/mralek
//
// Copyright © 2016 Alek Åström
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@MrAlek
MrAlek / hamburger.swift
Created December 6, 2015 19:09
Example of how to use presentation, animation & interaction controllers w/ custom segues to create a slide-in modal menu which partially covers presenting view.
import UIKit
enum Direction {
case Left, Right, Up, Down
var pointVector: CGPoint {
switch self {
case Left: return CGPoint(x: -1, y: 0)
case Right: return CGPoint(x: 1, y: 0)
case Up: return CGPoint(x: 0, y: -1)
func setupAnalytics() {
MasterViewController.self >> "Start"
AuthorViewController.self >> { "Author: \($0.author.name)" }
SettingsViewController.self >> "Settings"
OtherViewController.pageNameFunction<< // With currying!
}
@MrAlek
MrAlek / HairlineView
Last active December 8, 2016 16:55
A simple, @IBDesignable view which draws a pixel wide hairline of chosen color in chosen direction
import Foundation
import UIKit
import QuartzCore
enum HairlineDirection: Int {
case Left, Right, Top, Bottom, None
init(point: CGPoint) {
if point.x < 0 {
self = Left
@MrAlek
MrAlek / NSArray+TransformerBlock.m
Created April 19, 2014 11:52
NSArray+TransformerBlock
//
// Copyright (c) 2014 Alek Åström
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
@MrAlek
MrAlek / gist:10486763
Created April 11, 2014 17:36
iOS Root view controller architecture example
@interface RootViewController : UIViewController
// Child view controllers
@property (nonatomic) MenuViewController *menuViewController; // Hamburger menu
@property (nonatomic) UINavigationController *mainNavigationController; // Main UI
- (void)presentTutorial; // Or first time user registration, etc. Called from the app delegate.
@end