This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang -framework Foundation -fobjc-arc -O3 test.m | |
#import <Foundation/Foundation.h> | |
@interface Slice : NSObject | |
@property NSInteger start; | |
@property NSInteger length; | |
@end | |
@implementation Slice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)pulseView:(UIView *)view completion:(void (^)(void))block { | |
// if you use auto layout, view-based transform go haywire, as they trigger layoutSubviews | |
// consequence is that you have no idea where the view will end up on the screen once animation completes | |
// see this discussion: http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used | |
// thus (per solution 4 from link above), rewriting with CAKeyframeAnimation | |
CAKeyframeAnimation *ka = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; | |
ka.duration = .49; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from the commercial iOS PDF framework http://pspdfkit.com. | |
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved. | |
// Licensed under MIT (http://opensource.org/licenses/MIT) | |
// | |
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it. | |
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit. | |
#import <objc/runtime.h> | |
#import <objc/message.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern uint32_t dyld_get_program_sdk_version() WEAK_IMPORT_ATTRIBUTE; | |
extern BOOL DZApplicationUsesLegacyUI(void) | |
{ | |
static dispatch_once_t onceToken; | |
static BOOL legacyUI = NO; | |
dispatch_once(&onceToken, ^{ | |
uint32_t sdk = __IPHONE_OS_VERSION_MIN_REQUIRED; | |
if (dyld_get_program_sdk_version != NULL) { | |
sdk = dyld_get_program_sdk_version(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" File: reveal.py | |
Add to ~/.lldbinit: | |
command script import ~/.lldb-scripts/reveal.py | |
Q: Want to automatically load the Reveal lib on launch while debugging from Xcode? | |
A: In Xcode: | |
Add a Symbolic Breakpoint | |
Symbol: "UIApplicationMain" | |
Action: Debugger Command with value "reveal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath { | |
return @"More"; | |
} | |
- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath { | |
NSLog(@"I wanted to be a pretty public API, but then time ran out and they forgot me..."); | |
// Hide the More/Delete menu. | |
[self setEditing:NO animated:YES]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
func first() -> Element? { | |
if isEmpty { | |
return nil | |
} | |
return self[0] | |
} | |
func last() -> Element? { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: @schwa figured this out, but I'm claiming some of the credit for asking the question. | |
// See https://gist.github.com/schwa/ecd5f8c154e60fcb0f58 for the original solution. | |
// Playground - noun: a place where people can play | |
import Foundation | |
// Implementation (repeat as needed for number of parameters). | |
func unwrap<T1, T2>(p1: T1?, p2: T2?) -> (T1, T2)? { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
NSDictionary *TestD(void) { | |
return @{ | |
@"string" : @"abc", | |
@"number" : @42, | |
@"dictionary" : @{ | |
@"string" : @"abcdef", | |
@"array" : @[ @"a", @2 ] | |
}, |
OlderNewer