Skip to content

Instantly share code, notes, and snippets.

View Noobish1's full-sized avatar

Blair McArthur Noobish1

View GitHub Profile
// Option without self
class Foo1 {
private let controller: UIViewController = {
return UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()!
}()
private lazy var window: UIWindow = {
let window = UIWindow(frame: UIScreen.mainScreen().bounds)
window.backgroundColor = UIColor.whiteColor()
window.makeKeyAndVisible()
@rnystrom
rnystrom / RN3DTouchGestureRecognizer.swift
Last active February 3, 2018 22:58
RN3DTouchGestureRecognizer
//
// RN3DTouchGestureRecognizer.swift
//
// Created by Ryan Nystrom on 10/10/15.
// Copyright © 2015 Ryan Nystrom. All rights reserved.
//
import UIKit.UIGestureRecognizerSubclass
class RN3DTouchGestureRecognizer: UIGestureRecognizer {
@beccadax
beccadax / Example.swift
Last active March 6, 2020 16:10
Elegant handling of localizable strings in Swift. Note: This code is in Swift 2 and would need updates to be used in modern Swift.
let color = "blue"
let num = 42
localized("Colorless green ideas sleep furiously.")
localized("Colorless \(color) ideas sleep furiously.")
localized("\(num.formatted("%05d")) colorless green ideas sleep furiously.")
// If we extend UnicodeScalar to conform to ForwardIndexType, we can create and map a Range.
extension UnicodeScalar: ForwardIndexType {
public func successor() -> UnicodeScalar {
return UnicodeScalar(value + 1)
}
}
let alphabet = ("A"..."Z" as Range).map { String($0) }
// ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
// CONSTRUCTING ALPHABET ARRAY
// This my favorite because it's easily used with any character set
extension NSCharacterSet {
var members: [String] {
let unichars = Array(unichar(0)..<unichar(128)).filter({self.characterIsMember($0)})
return unichars.map({String(UnicodeScalar($0))})
}
}
@smileyborg
smileyborg / Xcode7Macros.h
Last active May 26, 2020 12:08
Backwards compatible macros for Objective-C nullability annotations and generics
/**
* The following preprocessor macros can be used to adopt the new nullability annotations and generics
* features available in Xcode 7, while maintaining backwards compatibility with earlier versions of
* Xcode that do not support these features.
*/
#if __has_feature(nullability)
# define __ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
# define __ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
# define __NULLABLE nullable
@0xced
0xced / UIClassSwapper.m
Last active November 1, 2023 01:41
Reverse engineered implementation of -[UIClassSwapper initWithCoder:]
@implementation UIClassSwapper
- (instancetype) initWithCoder:(UINibDecoder *)decoder
{
NSString *className = [decoder decodeObjectForKey:@"UIClassName"];
NSString *originalClassName = [decoder decodeObjectForKey:@"UIOriginalClassName"];
Class class = NSClassFromString(className);
Class originalClass = NSClassFromString(originalClassName);
@tLewisII
tLewisII / ForcePopover
Created May 2, 2015 17:51
Changes in iOS 8.3 breaks older forced popover code.
// Need both of these, since one `adaptivePresentationStyleForPresentationController:` works on 8.0 to 8.2, and the other,
// `adaptivePresentationStyleForPresentationController:traitCollection:` works on 8.3 plus
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
return UIModalPresentationNone;
}
//
// AppDelegate.swift
// TypedTableViewControllers
//
// Created by Chris Eidhof on 23/03/15.
// Copyright (c) 2015 Unsigned Integer. All rights reserved.
//
import UIKit