Skip to content

Instantly share code, notes, and snippets.

View shaps80's full-sized avatar
🏠
Working from home

Shaps shaps80

🏠
Working from home
View GitHub Profile
@shaps80
shaps80 / SLBarButtonItem.h
Last active December 18, 2015 14:29
I've often found myself a more convenient way to add a simple barButtonItem to a navigation or tool bar, so I created this nice little subclass.
#import <UIKit/UIKit.h>
@class SLBarButtonItem;
typedef void (^SLBarButtonItemCompletionBlock)(SLBarButtonItem *sender);
@interface SLBarButtonItem : UIBarButtonItem
+(SLBarButtonItem *)barButtonSystemItem:(UIBarButtonSystemItem)systemItem;
+(SLBarButtonItem *)barButtonWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style;
@shaps80
shaps80 / EncodingDefines.h
Last active December 19, 2015 13:49
Custom macros to provide better handling of encoding and decoding values. See my blog post for more detailed information: http://shaps.me/to-encode-or-to-decode
/*
Copyright (c) 2014 Shaps Mohsenin. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@shaps80
shaps80 / SPXDefines.h
Last active December 19, 2015 15:29
This is a common definitions file I use across many projects for convenience.
/*
Copyright (c) 2013 Snippex. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@shaps80
shaps80 / ImplementsSelectorSample.m
Last active December 21, 2015 08:38
Determine if a subclass implements a specific selector.
if ([MyView implementsSelector:@selector(someMethod:)])
NSLog(@"Implemented");
@shaps80
shaps80 / UINavigationController-Gesture.m
Last active September 23, 2020 08:35
Custom UINavigationController back button item, without losing iOS 7 swipe back gesture.
navigationController
.interactivePopGestureRecognizer
.delegate = (id<UIGestureRecognizerDelegate>)navigationController;
@shaps80
shaps80 / SPXGeometry.m
Created September 25, 2013 10:31
CGRectDivide with Padding
void CGRectDivideWithPadding(CGRect rect, CGRect *slide, CGRect *remainder, CGFloat amount, CGFloat padding, CGRectEdge edge)
{
CGRect rect1, rect2;
CGRectDivide(rect, &rect1, &rect2, amount, edge);
if (edge == CGRectMaxXEdge || edge == CGRectMaxYEdge)
{
CGRect tmp = rect1;
rect1 = rect2;
rect2 = tmp;
@shaps80
shaps80 / NSAttributedString+SPXAdditions.h
Created September 25, 2013 10:46
NSAttributedString Category to add more flexible customisation.
/*
Copyright (c) 2013 Snippex. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@shaps80
shaps80 / NSOperation+SPXAdditions.m
Created September 25, 2013 10:50
LIFO NSOperationQueue
/*
Copyright (c) 2013 Snippex. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@shaps80
shaps80 / Logging.h
Last active January 3, 2016 21:39
Provides better logging with pretty formatting custom timestamp formatting. Fully customisable, and easy drop in replacement to start tidying up existing logs. No additional or frameworks required! Simply replace all NSLog occurrences with SPXLog and watch the logs get prettier! ;)
#import <Foundation/Foundation.h>
#ifdef __SPXLOGGING
#define __SPXLOGGING
/**
* Custom C function for getting the current date/time.
* This function provides custom formatting and is much faster than using
* NSDate and NSDateFormatter, which a lot of log messages are sent.
* Also this way there's little additional memory overhead during logging.
@shaps80
shaps80 / InitWithException.m
Created January 22, 2014 16:47
ProTip: Better way to raise an exception when -init is called on a class that implements a designated initialiser. Turn on -Wstrict-selector-match to get compiler warnings when this selector doesn't exist. Some IDEs (like AppCode) will even refactor this for you should you change the selector ;) The best thing about this is if its inside a stati…
- (instancetype)init
{
SEL selector = @selector(initWithName:);
[NSException raise:NSGenericException format:@"Please use %@", NSStringFromSelector(selector)];
return nil;
}
- (instancetype)initWithName:(NSString *)name
{
self = [super init];