Skip to content

Instantly share code, notes, and snippets.

View mrtj's full-sized avatar

Janos Tolgyesi mrtj

View GitHub Profile
@mrtj
mrtj / TJIntegerArray.h
Last active July 18, 2018 19:47
Simple Objective C wrapper around a C integer array. Supports fast enumeration via NSNumber objects. #integer #array #objective-c License: BSD
// Author: janos.tolgyesi@gmail.com
// License: BSD
#import <Foundation/Foundation.h>
@interface TJIntegerArray : NSObject <NSFastEnumeration>
{
NSInteger* _array;
}
@mrtj
mrtj / NSString+RandomFileName.h
Created February 12, 2013 09:41
Utility class extension for creating random / temporary file names in one of the common directories of the current user's domain. #utility #nsstring #filename #random #objective-c
#import <Foundation/Foundation.h>
@interface NSString (RandomFileName)
+(NSString*)randomString;
+(NSString*)randomFileNameWithExtension:(NSString*)extension;
+(NSString*)randomFileNameInDirectory:(NSSearchPathDirectory)directory withExtension:(NSString*)extension;
@end
@mrtj
mrtj / NSString+URLEncoding.h
Last active December 12, 2015 10:48
URL encoding and decoding utility class extension for NSString #nsstring #utility #url-encoding #url-decoding #objective-c
#import <Foundation/Foundation.h>
@interface NSString (URLEncoding)
- (NSString*)URLEncodedString;
- (NSString*)URLDecodedString;
@end
@mrtj
mrtj / UIImage+Retina4.h
Created February 15, 2013 11:56
Extends [UIImage imageNamed:] method to consider also -568h@2x suffices of images targeted for Retina 4" devices. #iOS #objective-c #retina #ui #utility
#import <UIKit/UIKit.h>
@interface UIImage (Retina4)
+ (UIImage *)imageNamedRetina4:(NSString *)imageName;
@end
@mrtj
mrtj / TJSettingsManager.h
Last active December 14, 2015 04:39
A wrapper class around NSUserDefaults that adds compile time type and spell check to keys stored in user defaults. Usage: inherit from this class and define your properties in your header (currently only NSInteger and BOOL types are supported). In the implementation mark all properties as @dynamic much like in managed object derivates. All of yo…
#import <Foundation/Foundation.h>
@interface TJSettingsManager : NSObject
{
NSUserDefaults* _userDefaults;
}
+(id)sharedInstance;
-(void)save;
@mrtj
mrtj / UIImageView+OfflineCache.h
Created March 6, 2013 09:18
UIImageView category to download images asynchronously using the cache policy of the HTTP server if it is reachable otherwise look up for the image resource in the local HTTP cache. Depends on AFNetworking UIImageView category and Reachability components. #utils #image #UIImageView #cache #http #download
#import <UIKit/UIKit.h>
@interface UIImageView (OfflineCache)
-(void)setImageCachedWithURL:(NSURL*)url
placeholderImage:(UIImage *)placeholderImage
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
@end
@mrtj
mrtj / TJXMLParser.h
Last active December 14, 2015 18:59
Simple DOM based XML parser #cocoa #xml #parser #utils #dom
#import <Foundation/Foundation.h>
@interface TJXMLElement : NSObject
@property (nonatomic, readonly) NSString* name;
@property (nonatomic, readonly) NSDictionary* attributes;
@property (nonatomic, retain) NSMutableArray* children;
@property (nonatomic, retain) NSMutableString* text;
- (id) initWithName:(NSString*)name withAttributes:(NSDictionary*)attributes;
@mrtj
mrtj / RectUtils.h
Last active December 15, 2015 05:49
Simple CGRect utils #core-graphics #objective-c #utils #cgrect
#ifndef RECTUTILS_H
#define RECTUTILS_H
#include <CoreGraphics/CGGeometry.h>
CG_INLINE CGRect CGRectChangeSize(CGRect rect, CGSize size);
CG_INLINE CGRect CGRectChangeWidth(CGRect rect, CGFloat width);
CG_INLINE CGRect CGRectChangeHeight(CGRect rect, CGFloat height);
CG_INLINE CGRect CGRectChangeOrigin(CGRect rect, CGPoint origin);
@mrtj
mrtj / UIColorFromRGB.h
Last active December 16, 2015 05:59
UIColor from 0x123456 style unsigned integer
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@mrtj
mrtj / NSURL+QueryParser.h
Created May 20, 2013 15:58
NSURL category to parser GET parameters from the URL into a NSDictionary #objective-c #utils #url
#import <Foundation/Foundation.h>
@interface NSURL (QueryParser)
-(NSDictionary*)queryDictionary;
@end