Skip to content

Instantly share code, notes, and snippets.

@olegam
olegam / gist:8997427
Created February 14, 2014 08:08
AppCode code template to implement lazy-loaded property getters

This template let's you easily implement a property getter like this:

- (UIView *)myView {
	if (!_myView) {
		_myView = [UIView new];
	}
	return _myView;
}
@krzysztofzablocki
krzysztofzablocki / Safe nil calls in server code
Created December 19, 2012 12:36
Simplified check as nil is fine
#define SafeCall(arg, methodToCall) (arg !=[NSNull null]) ? [arg methodToCall] : nil
int optionalValue = SafeCall([response valueForKey:@"number"], intValue);
@ejknapp
ejknapp / gist:4580156
Created January 20, 2013 17:41
Enable zooming in mobile browsers.
javascript:document.querySelector('meta[name=viewport]').setAttribute('content','width=device-width,initial-scale=1.0,maximum-scale=10.0,user-scalable=1');
// 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
@jspahrsummers
jspahrsummers / gist:5812222
Last active December 18, 2015 16:29
Make "self" cause a compilation error only within blocks.
#define self \
( \
_Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wunused-value\"") self, \
/* Depends on _cmd being a const copy, like other captured variables. */ \
_Pragma("clang diagnostic pop") (*(_cmd = _cmd, &self)) \
)
// Replace libextobjc's @weakify with one that's aware of the "self" macro.
#undef ext_weakify_
#define ext_weakify_(INDEX, CONTEXT, VAR) \
@mbigatti
mbigatti / AddDynamicProperty.h
Last active December 24, 2015 05:29
A macro for dynamic properties in categories
//
// Dynamic properties in categories
//
// @see http://www.davidhamrick.com/2012/05/28/Adding-Properties-to-an-Objective-C-Category-Revisted.html
// @see https://twitter.com/nicklockwood/status/384088702768922625
// @see http://www.tuaw.com/2013/04/10/devjuice-better-objective-c-associated-objects/
// @see http://stackoverflow.com/questions/16020918/avoid-extra-static-variables-for-associated-objects-keys
//
// Remember to add #import <objc/runtime.h> in implementation.
//
@jfahrenkrug
jfahrenkrug / wwdc2013.rb
Last active February 9, 2017 04:38
Ruby Script to check whether WWDC 2013 has been announced.
# in 2013 by Johannes Fahrenkrug, http://springenwerk.com
# See you at WWDC!
require 'rubygems'
require 'open-uri'
class WWDC2013
def self.announced?
begin
indicator_line = open('https://developer.apple.com/wwdc/') do |f|
@nicklockwood
nicklockwood / gist:7447381
Last active February 14, 2017 09:31
Why I still prefer nibs to storyboards.

Storyboard Segues initially seem like a pretty cool way to construct interfaces using minimal glue code. But actually, ordinary nibs already support this, and in a much more flexible way.

Certainly, a Storyboard lets you bind a button action up to display a view controller with no code, but in practice you will usually want to pass some data to the new controller, depending on which button you used to get there, and this means implementing the -prepareForSegue:sender: method, which rapidly becomes a giant if/elseif statement of doom, negating most of the benefit of the codeless segue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"modalSegue"])
    {
        ModalViewController *controller = (ModalViewController *)segue.destination;

controller.someProperty = someValue;

@steipete
steipete / PSPDFViewController.h
Last active June 6, 2017 03:56
This method will help to prevent a lot of emails about "weird bugs".
// 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
@interface UIViewController (SubclassingWarnings)
@steventroughtonsmith
steventroughtonsmith / gist:6763213
Created September 30, 2013 12:39
Non-opaque application windows in iOS 7, with optional blur. Shows the user's wallpaper under the app, with Parallax if supported.
typedef enum _UIBackgroundStyle {
UIBackgroundStyleDefault,
UIBackgroundStyleTransparent,
UIBackgroundStyleLightBlur,
UIBackgroundStyleDarkBlur,
UIBackgroundStyleDarkTranslucent
} UIBackgroundStyle;
@interface UIApplication (UIBackgroundStyle)
-(void)_setBackgroundStyle:(UIBackgroundStyle)style;