Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Shaps shaps80

🏠
Working from home
View GitHub Profile
@shaps80
shaps80 / SLBarButtonItem.h
Last active Dec 18, 2015
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.
View SLBarButtonItem.h
#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 Dec 19, 2015
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
View EncodingDefines.h
/*
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 Dec 19, 2015
This is a common definitions file I use across many projects for convenience.
View SPXDefines.h
/*
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 Dec 21, 2015
Determine if a subclass implements a specific selector.
View ImplementsSelectorSample.m
if ([MyView implementsSelector:@selector(someMethod:)])
NSLog(@"Implemented");
@shaps80
shaps80 / UINavigationController-Gesture.m
Last active Sep 23, 2020
Custom UINavigationController back button item, without losing iOS 7 swipe back gesture.
View UINavigationController-Gesture.m
navigationController
.interactivePopGestureRecognizer
.delegate = (id<UIGestureRecognizerDelegate>)navigationController;
@shaps80
shaps80 / SPXGeometry.m
Created Sep 25, 2013
CGRectDivide with Padding
View SPXGeometry.m
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 Sep 25, 2013
NSAttributedString Category to add more flexible customisation.
View NSAttributedString+SPXAdditions.h
/*
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,
View NSOperation+SPXAdditions.m
/*
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 Jan 3, 2016
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! ;)
View Logging.h
#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 Jan 22, 2014
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…
View InitWithException.m
- (instancetype)init
{
SEL selector = @selector(initWithName:);
[NSException raise:NSGenericException format:@"Please use %@", NSStringFromSelector(selector)];
return nil;
}
- (instancetype)initWithName:(NSString *)name
{
self = [super init];