Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Alex Pretzlav Pretz

🎯
Focusing
View GitHub Profile
@Pretz
Pretz / parameterized_enum.swift
Created Jul 10, 2014
parameterized enums in swift that don't crash xcode
View parameterized_enum.swift
// Playground - noun: a place where people can play
import Foundation
struct ResultType<T: NSObject> {
var _value: [T]
var value: T {
get {
return _value[0]
@Pretz
Pretz / components.md
Created Sep 24, 2014
iOS Calendar UI Components
View components.md

I went searching for a UI component that shows a single month at a time and allows switching between months. I decided to roll my own, but here's the projects I looked at, ordered by github stars:

  1. https://github.com/devinross/tapkulibrary (3492)
  2. https://github.com/square/objc-TimesSquare (1366)
  3. https://github.com/klazuka/Kal (1259)
  4. https://github.com/min/MNCalendarView (317)
  5. https://github.com/PeteC/DSLCalendarView (290)
  6. https://github.com/MosheBerman/MBCalendarKit (287)
  7. https://github.com/phaibin/Kal (64)
View generic_callback.swift
// Playground - noun: a place where people can play
import UIKit
struct ApiResponse {
let success: Bool
let values: [[NSObject: AnyObject]]
}
class BaseModel: NSObject {
@Pretz
Pretz / let-case.swift
Created Oct 24, 2014
Best way to initialize a `let` variable using a case statement?
View let-case.swift
let inView: UIView = {
switch display {
case .InWindow:
return self.view.window!
case .AboveKeyboard:
return UIApplication.sharedApplication().windows[1] as UIView
default:
return self.view
}
}()
@Pretz
Pretz / keybase.md
Created Oct 28, 2014
Verifying myself
View keybase.md

Keybase proof

I hereby claim:

  • I am pretz on github.
  • I am pretz (https://keybase.io/pretz) on keybase.
  • I have a public key whose fingerprint is 9B4A E36E 43C7 87E1 EAD1 2B6A 6D83 84D4 CFE7 7658

To claim this, I am signing this object:

View .clang-format.yaml
BasedOnStyle: Chromium
IndentWidth: 4
UseTab: Never
ColumnLimit: 150
ObjCSpaceAfterProperty: true
PointerBindsToType: false
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: true
SpacesInContainerLiterals: false
AllowShortFunctionsOnASingleLine: false
View obj-c-convenience-init.swift
import Foundation
class MyDictionary : NSDictionary {
convenience init(beAwesome:Bool) {
if (beAwesome) {
self.init(object: true, forKey:"awesome")
} else {
self.init(object: false, forKey:"awesome")
}
}
@Pretz
Pretz / ModelFactory.swift
Created Jan 28, 2015
strongly typed mock model constructor for Swift tests
View ModelFactory.swift
struct MockFile<T> {
let fileName: String
init(_ fileName: String) {
self.fileName = fileName
}
}
struct Mocks {
static let UserWithProfile = MockFile<User>("registrations_mock")
@Pretz
Pretz / override.swift
Created Feb 23, 2015
Swift 1.2 override
View override.swift
import Foundation
class Something: NSObject {
func fun(string: String) {
println(string)
}
// error: method 'fun' redeclares Objective-C method 'fun:'
func fun(int: Int) {
View LumaJSON.swift
// Playground - noun: a place where people can play
import UIKit
class LumaJSONObject: Printable {
var value: AnyObject?
subscript(index: Int) -> LumaJSONObject? {
return (value as? [AnyObject]).map { LumaJSONObject($0[index]) }
}