Skip to content

Instantly share code, notes, and snippets.

View iosdevzone's full-sized avatar

idz iosdevzone

View GitHub Profile
import UIKit
///
///Declaration
///
protocol UIViewBuilder: AnyObject {}
extension UIViewBuilder where Self: UIView {
init(_ build: ((Self) -> Void)) {
@cabeca
cabeca / simulator_populator
Created September 23, 2014 21:30
This script removes and recreates all simulators in Xcode 6.
#!/usr/bin/env ruby
device_types_output = `xcrun simctl list devicetypes`
device_types = device_types_output.scan /(.*) \((.*)\)/
runtimes_output = `xcrun simctl list runtimes`
runtimes = runtimes_output.scan /(.*) \(.*\) \((com.apple[^)]+)\)$/
devices_output = `xcrun simctl list devices`
devices = devices_output.scan /\s\s\s\s(.*) \(([^)]+)\) (.*)/
@iosdevzone
iosdevzone / gist:5676451
Created May 30, 2013 08:17
Leveraging the preprocessor to lessen boilerplate. L(X) is the crux. It allows the me to apply different transformations over the same list.
#define S(_s) @selector(application##_s:) // selector generator
#define N(_n) UIApplication##_n##Notification // name generator
#define L(X) X(WillResignActive), X(DidEnterBackground), \
X(WillEnterForeground), X(DidBecomeActive), X(WillTerminate) // apply X over list
#define C(_a) sizeof((_a))/sizeof((_a)[0]) // array count
- (void)monitorAppState:(BOOL)start
{
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
// Defines a yet undocumented method to add a warning if super isn't called.
#ifndef NS_REQUIRES_SUPER
#if __has_attribute(objc_requires_super)
#define NS_REQUIRES_SUPER __attribute((objc_requires_super))
#else
#define NS_REQUIRES_SUPER
#endif
#endif