Skip to content

Instantly share code, notes, and snippets.

View shaps80's full-sized avatar
🔥
Work with me!

Shaps shaps80

🔥
Work with me!
View GitHub Profile
@shaps80
shaps80 / SPXEncodingDefines.h
Created March 13, 2014 13:54
NSCoding and NSUserDefaults Defines - Clean macros to simplify your life
/*
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,
typedef NS_ENUM(NSInteger, kErrorCode) {
kErrorCodeInternal = 431432,
};
extern NSError *NSErrorMake(NSString *message, NSInteger code, NSDictionary *aUserInfo, NSString *methodOrFunction);
#define NSObjcAssert NSAssert
#define InvalidConditionString(condition) (@"Invalid condition not satisfying: " #condition)
#define GenericAssertCondition(ctype, condition) NS ## ctype ## Assert((condition), InvalidConditionString((condition)))
#define GenericErrorMake(condition, func) NSErrorMake(InvalidConditionString((condition)), kErrorCodeInternal, nil, func)

Keybase proof

I hereby claim:

  • I am shaps80 on github.
  • I am shaps (https://keybase.io/shaps) on keybase.
  • I have a public key whose fingerprint is D1B3 44E7 F8A9 EF64 D1E0 4292 4286 651A F5BD CB47

To claim this, I am signing this object:

@shaps80
shaps80 / UIView+OptionalAnimations.h
Last active August 29, 2015 14:00
Added transitions
@interface UIView (SPXAdditions)
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration animations:(void (^)(void))animations;
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
+ (void)animate:(BOOL)shouldAnimate duration:(CGFloat)duration delay:(CGFloat)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion;
+ (void)animate:(BOOL)shouldAnimate duration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL))completion;
+ (void)transition:(BOOL)shouldTransition fromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL))completion;
+ (void)transition:(BOOL)shoul
@shaps80
shaps80 / AsyncKiwiTest.m
Created May 22, 2014 18:31
The following is the test I have written but it never asserts from my tests. I think the issue is that the assertion occurs on a different thread that the one that the task is performed on, that perhaps this isn't getting back to the test.
it (@"should eventually throw assert for asynchronous operation", ^{
[[theBlock(^{
[MyClass performLongRunningAsynchronousTasks];
}) shouldEventually] raise];
});
@shaps80
shaps80 / UIApplication+SnippexAdditions.h
Last active August 29, 2015 14:22
Check if running inside an App Extension vs an App
@import Foundation;
@interface UIApplication (SnippexAdditions)
+ (BOOL)isAppExtension;
@end
@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");