Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
lukeredpath / LICENSE
Last active March 22, 2020 08:21
A decorator around UILocalizedIndexedCollation that automatically adds the search icon. Updated to support ARC.
Copyright (c) 2010 Luke Redpath
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:
The above copyright notice and this permission notice shall be included in

Objective-C Coding Convention and Best Practices

Most of these guidelines are to match Apple's documentation and community-accepted best practices. Some are derived some personal preference. This document aims to set a standard way of doing things so everyone can do things the same way. If there is something you are not particularly fond of, it is encouraged to do it anyway to be consistent with everyone else.

This document is mainly targeted toward iOS development, but definitely applies to Mac as well.

Operators

NSString *foo = @"bar";
@pk
pk / ExampleTest.m
Created June 21, 2011 15:00
Using method swizzling and blocks to test Class methods in Objective-C.
#import "SenTestCase+MethodSwizzling.m"
@interface ExampleTest : SenTestCase {}
+ (BOOL)trueMethod;
+ (BOOL)falseMethod;
@end
@implementation ExampleTest
+ (BOOL)trueMethod { return YES; }
@eric-robinson
eric-robinson / gist:1614732
Created January 15, 2012 06:36
Setup Core Data SQLite db for use with iCloud
//Some scattered methods for setting up iCloud storage of a SQLite Core Data managed database.
//define your ubiquity container id
-(NSString*)ubiquityContainerIdentifier {
//should match what is in your app's entitlement file
return [NSString stringWithFormat:@"%@.%@", @"<YOUR TEAM IDENTIFIER>", [[NSBundle mainBundle] bundleIdentifier]];
}
//where you're going to store your database
@0xced
0xced / XCDFakeCarrier.m
Last active March 5, 2023 22:07
Hack to choose the displayed carrier name in the iOS simulator
//
// Copyright (c) 2012-2015 Cédric Luthi / @0xced. All rights reserved.
//
#import <Foundation/Foundation.h>
#if TARGET_OS_SIMULATOR
static const char *fakeCarrier;
static const char *fakeTime;
anonymous
anonymous / gist:4468522
Created January 6, 2013 16:53
+ (void)pulseView:(UIView *)view completion:(void (^)(void))block {
// No need for fancy keyframe animation, we can fake this good enough...
[UIView animateWithDuration:0.05 delay:0 options:UIViewAnimationCurveEaseInOut animations:^(void) {
view.layer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(0.7, 0.7));
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.12 delay:0 options:UIViewAnimationCurveEaseInOut animations:^(void) {
view.layer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(1.1, 1.1));
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationCurveEaseInOut animations:^(void) {
@irace
irace / gist:5216137
Last active December 15, 2015 06:28
Core Data migrations are hard. If you don't need to migrate, then don't! Here's how:
/*
Core Data is great but automatic migrations can be tricky. Migrations can take a long time, which could
result in [your app being terminated](http://stackoverflow.com/questions/13333289/core-data-timeout-adding-persistent-store-on-application-launch)
if it is happening on the main thread during application launch. Performing migrations on a background
thread is also a [bad idea](http://stackoverflow.com/a/2866725/503916), meaning your application really
needs to be able to fully launch *without a Core Data stack whatsoever* in order to safely migrate.
This can be a huge change to make to an existing app.
If you're really only using Core Data as a cache, you don't actually *need* to perform a migration.
Simply check if the existing store is compatible with your managed object model and if so, delete
@stuffmc
stuffmc / gist:5271713
Created March 29, 2013 15:54
RAPageViewControllerSubclass code necessary for getting scrollsToTop back at work. Unless @evadne sees a better solution.
- (void)viewDidLoad {
[super viewDidLoad];
[self scrollView].scrollsToTop = NO;
[self scrollView].delegate = self;
...
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[super scrollViewDidEndDecelerating:scrollView];
@eternalstorms
eternalstorms / Apple Evangelists.txt
Created June 12, 2013 09:07
Apple Evangelists (WWDC 2013)
UI- and App Frameworks Evangelist - Jake Behrens, behrens@apple.com, twitter: @Behrens
- What's new in Cocoa
- Accessibility in iOS
- Building User Interfaces for iOS 7
- Getting Started with UIKit Dynamics
- What's new in Cocoa Touch
- What's New With Multitasking
- Best Practices for Cocoa Animation
- Improving Power Efficiency with App Nap
- Introducing Text Kit
@drance
drance / UIViewController+BHSContainment.m
Last active September 2, 2021 00:26
Tired of the UIViewController containment three-step. Adds a convenience param if the destination superview is not actually the parent VC's main view.
@implementation UIViewController (BHSContainment)
- (void)bhs_addChildViewController:(UIViewController *)child {
[self bhs_addChildViewController:child superview:self.view];
}
// Note this potentially forces view loads on both parent and child
// Not a problem if used in -viewDidLoad or later
// Use superview parameter with care. If it's not within the parent VC's hierarchy, you deserve to lose