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
!!! There's a better solution here now, that doesn't require swizzling: | |
!!! http://www.splinter.com.au/2014/09/10/afnetworking-error-bodies/ | |
!!! But i'll leave the below swizzling solution up for old time's sake | |
// AFURLSessionManager+ErrorResponse.h | |
// This hacks AFURLSessionManager so that it returns the error response in failure callbacks, in the error's userInfo. | |
// Usage: | |
// [mySessionManager POST:@"some_api_endpoint" parameters:params success:^(NSURLSessionDataTask *task, NSDictionary *responseObject) { |
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 UIKit | |
extension UIColor { | |
/// Creates a UIColor from an 'rrggbb' hex string. | |
class func fromHex(hexColour: String) -> UIColor { | |
let str = hexColour.cStringUsingEncoding(NSUTF8StringEncoding) | |
let x = strtol(str!, nil, 16) | |
let r = x >> 16 | |
let g = (x >> 8) & 0xff |
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 | |
/// Since there can be multiple delegates, they can only be used to signifying events (output), not for | |
/// supplying data for the manager (input). | |
@objc protocol MyManagerDelegate { | |
func manager(manager: MyManager, isNowLoading: Bool) | |
} | |
@objc class MyManager { |
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
// | |
// Keychain.swift | |
// SwiftKeychain | |
// | |
// Created by Chris Hulbert on 14/06/2015. | |
// Copyright (c) 2015 Chris Hulbert. All rights reserved. | |
// | |
import Foundation | |
import Security |
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 | |
import Security | |
struct SecItemWrapper { | |
static func matching(query: NSDictionary) -> (status: Status, result: AnyObject?) { | |
var rawResult: Unmanaged<AnyObject>? | |
let rawStatus = SecItemCopyMatching(query, &rawResult) | |
let result: AnyObject? = rawResult?.takeRetainedValue() | |
let status = Status.fromOSStatus(rawStatus) | |
return (status, result) |
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*)urlEscape:(NSString *)unencodedString { | |
NSString *s = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, | |
(CFStringRef)unencodedString, | |
NULL, | |
(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ", | |
kCFStringEncodingUTF8); | |
return [s autorelease]; // Due to the 'create rule' we own the above and must autorelease it | |
} | |
// Put a query string onto the end of a url |
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
@interface SizableImageCell : UITableViewCell {} | |
@end | |
@implementation SizableImageCell | |
- (void)layoutSubviews { | |
[super layoutSubviews]; | |
float desiredWidth = 80; | |
float w=self.imageView.frame.size.width; | |
if (w>desiredWidth) { | |
float widthSub = w - desiredWidth; |
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
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 9999)]; | |
myLabel.lineBreakMode = UILineBreakModeWordWrap; | |
myLabel.numberOfLines = 0; | |
myLabel.text = @"Some \n dynamic \n multiline \n text"; | |
[myLabel sizeToFit]; // This shrinks the 9999 down to the size of the text | |
NSLog(@"Actual height is: %f", myLabel.frame.size.height); // Use this for spacing any further elements | |
[self.view addSubview:title]; // Or add it to a scroll view, or whatever... | |
[myLabel release]; |
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
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { | |
UILabel *lbl = [[[UILabel alloc] init] autorelease]; | |
lbl.textAlignment = UITextAlignmentCenter; | |
lbl.font = [UIFont fontWithName:@"Helvetica-Bold" size:18]; | |
lbl.text = @"My Centered Header"; | |
lbl.textColor = [UIColor whiteColor]; | |
lbl.shadowColor = [UIColor grayColor]; | |
lbl.shadowOffset = CGSizeMake(0,1); | |
lbl.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"my_head_bg"]]; | |
lbl.alpha = 0.9; |
OlderNewer