Skip to content

Instantly share code, notes, and snippets.

View jeffbailey's full-sized avatar

Jeff Bailey jeffbailey

View GitHub Profile
@adamawolf
adamawolf / Apple_mobile_device_types.txt
Last active July 22, 2024 12:48
List of Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names
i386 : iPhone Simulator
x86_64 : iPhone Simulator
arm64 : iPhone Simulator
iPhone1,1 : iPhone
iPhone1,2 : iPhone 3G
iPhone2,1 : iPhone 3GS
iPhone3,1 : iPhone 4
iPhone3,2 : iPhone 4 GSM Rev A
iPhone3,3 : iPhone 4 CDMA
iPhone4,1 : iPhone 4S
@twobitlabs
twobitlabs / gist:4226365
Created December 6, 2012 17:35
Blocks cheat sheet
// http://cocoawithlove.com/2009/10/ugly-side-of-blocks-explicit.html has a nice breakdown of the syntax--it helps to think of the ^ as similar to a pointer dereference symbol *
// block typedef:
typedef void(^Block)();
typedef void(^ConditionalBlock)(BOOL);
typedef NSString*(^BlockThatReturnsString)();
typedef NSString*(^ConditionalBlockThatReturnsString)(BOOL);
// block property with typedef:
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active May 27, 2024 12:11
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// 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>
@steipete
steipete / PSPDFTextView.m
Created November 28, 2013 11:15
Works around the issue where UITextView doesn't scroll to the new line until there's a character in there. Super horrible workaround.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
// Horrible HACK for bug in UITextView where it won't scroll to the new line after pressing enter in the text view.
// I feel dirty for having to write this. Buggy at least within iOS 7.0 - 7.1b1.
if (PSPDFIsUIKitFlatMode() && [text isEqualToString:@"\n"] && range.location == textView.text.length) {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^{
CGPoint contentOffset = textView.contentOffset;
CGFloat fontSize = textView.font.pointSize;
if (textView.contentSize.height - fontSize > textView.bounds.size.height) {
contentOffset.y += fontSize + 2.f; // add spacing
/**
Provides the ability to verify key paths at compile time.
If "keyPath" does not exist, a compile-time error will be generated.
Example:
// Verifies "isFinished" exists on "operation".
NSString *key = SQKeyPath(operation, isFinished);
// Verifies "isFinished" exists on self.
@jeffbailey
jeffbailey / CircleUIImageViewMask
Created January 25, 2014 12:25
Mask an UIImageView to a circle.
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.imageView.layer.masksToBounds = YES;
self.imageView.layer.cornerRadius = self.imageView.bounds.size.width / 2.;
}
#import <objc/objc-runtime.h>
#import "UIView+SGAutoLayoutExtensions.h"
@implementation UIView (SGAutoLayoutExtensions)
#ifdef DEBUG
- (NSString *)nsli_description
{
return [self restorationIdentifier] ?: [NSString stringWithFormat:@"%@:%p", [self class], self];
@peeblesjs
peeblesjs / gist:9288f79322ed3119ece4
Last active February 11, 2016 23:31
A naive "valueForKey:" operator in Swift
operator infix --> {}
func --> (instance: Any, key: String) -> Any? {
let mirror = reflect(instance)
for index in 0 ..< mirror.count {
let (childKey, childMirror) = mirror[index]
if childKey == key {
return childMirror.value
}
}
Project # of Top 100 Free Apps (US)
facebook-ios-sdk 67
Bolts-iOS 48
AFNetworking 39
Google-Mobile-Ads-SDK 38
Reachability (Apple) 38
Crashlytics 37
Flurry-iOS-SDK 31
CocoaPods 30
GoogleConversionTracking 29
import Cocoa
// for-in
func checkForIn(array: [Int], dict: [Int: String]) {
for num in array where dict[num] != nil {
num
}
}
checkForIn([1,2,3,4], dict: [1:"one", 2:"two"])