Skip to content

Instantly share code, notes, and snippets.

View u10int's full-sized avatar

Nicholas Shipes u10int

View GitHub Profile
// Playground - noun: a place where people can play
import Cocoa
struct Regex {
let pattern: String
let expressionOptions: NSRegularExpressionOptions
let matchingOptions: NSMatchingOptions
init(pattern: String, expressionOptions: NSRegularExpressionOptions, matchingOptions: NSMatchingOptions) {
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {

Hacking UIView animation blocks for fun and profit

In this article, I'm going to explore a way that we can create views that implement custom Core Animation property animations in a natural way.

As we know, layers in iOS come in two flavours: Backing layers and hosted layers. The only difference between them is that the view acts as the layer delegate for its backing layer, but not for any hosted sublayers.

In order to implement the UIView transactional animation blocks, UIView disables all animations by default and then re-enables them individually as required. It does this using the actionForLayer:forKey: method.

Somewhat strangely, UIView doesn't enable animations for every property that CALayer does by default. A notable example is the layer.contents property, which is animatable by default for a hosted layer, but cannot be animated using a UIView animation block.

@u10int
u10int / IPInsetLabel.h
Created July 13, 2012 19:22
IPInsetLabel: a simple UILabel subclass that adds padding insets and auto-height-resizing
//
// IPInsetLabel.h
// Instapaper
//
// Created by Marco Arment on 7/23/11.
// Copyright 2011 Instapaper LLC, released to the public domain.
//
#import <UIKit/UIKit.h>
@u10int
u10int / ARCHelper.h
Created September 18, 2012 14:32 — forked from nicklockwood/ARCHelper.h
ARC Helper
//
// ARC Helper
//
// Version 2.1
//
// Created by Nick Lockwood on 05/01/2012.
// Copyright 2012 Charcoal Design
//
// Distributed under the permissive zlib license
// Get the latest version from here:
@implementation MKMapView (ZoomLevel)
- (NSUInteger) zoomLevel {
return (21 - round(log2(self.region.span.longitudeDelta * MERCATOR_RADIUS * M_PI / (180.0 * self.bounds.size.width))));
}
@end
@u10int
u10int / gist:4199467
Created December 4, 2012 00:46
Outputting Aeris Data in HW3
%%CODE __
$response = file_get_contents("http://api.aerisapi.com/observations/closest?p=%%zipcode%%&client_id= CLIENT_ID &client_secret= CLIENT_SECRET "); __
$json = json_decode($response); __
if ($json->success == true) { __
$Country = $json->response[0]->place->country; __
$cond = $json->response[0]->ob; __
echo ("<tr><td width='100%' colspan='2' align='center'><img src='%%hwvImagesPath%%" . ($tIcon=(!empty($cond->icon)) ? $cond->icon : "na.gif") . "' alt='" . $cond->weather . "' width='%%hwvImgWidth%%' height='%%hwvImgHeight%%' /></td></tr>"); __
echo ("<tr><td width='100%' colspan='2' align='center'><span class='Wx'>" . ($tWxshort=(!empty($cond->weatherShort)) ? $cond->weatherShort : "N/A") . "</span></td></tr>"); __
echo ("<tr><td valign='top'><span class='Temp'>Temp:</span></td><td valign='top' align='right'><span class='Temp'>" . ($tTemp=(!empty($cond->tempF)) ? (($Country == 'us') ? $cond->tempF : $cond->tempC) . "&deg;" : "N/A") . "</span></td></tr>"); __
echo ("</table></td><td valign='top' al
@u10int
u10int / iOS_API+Blocks.h
Created December 11, 2012 17:10 — forked from puppybits/iOS_API+Blocks.h
Replace common iOS delegate APIs with blocks
//
// iOS_API+Blocks.h
//
// Created by Bobby Schultz on 12/1/11.
@interface UIAlertView (PBBlocks)
+ (id) alertWithTitle:(NSString*)title
message:(NSString*)message
clickedBlock:(void(^)(NSInteger))buttonIndexClickedBlock

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'

UIActivityIndicatorView

@u10int
u10int / FRP iOS Learning resources.md
Created October 25, 2016 00:44 — forked from JaviLorbada/FRP iOS Learning resources.md
The best FRP iOS resources.

Videos