Skip to content

Instantly share code, notes, and snippets.

View albertodebortoli's full-sized avatar

Alberto De Bortoli albertodebortoli

View GitHub Profile
@albertodebortoli
albertodebortoli / bookCoverOpen.m
Created March 9, 2012 21:50
Book cover flip animation on iOS (Path app style)
#import <QuartzCore/QuartzCore.h>
UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:@"Default.png"];
[self.window addSubview:splashView];
[self.window bringSubviewToFront:splashView];
splashView.layer.anchorPoint=CGPointMake(0, .5);
splashView.center = CGPointMake(splashView.center.x - splashView.bounds.size.width/2.0f, splashView.center.y);
[UIView beginAnimations:nil context:nil];
@albertodebortoli
albertodebortoli / AppDelegate.m
Created March 9, 2012 22:16
iPhone splash screen fade out animation
// in application:didFinishLaunchingWithOptions: in app delegate
// before [window makeKeyAndVisible];
UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:@"background.png"];
// after [window makeKeyAndVisible];
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:@"Default.png"];
[window addSubview:splashView];
@albertodebortoli
albertodebortoli / gist:2017868
Created March 11, 2012 19:52
Xcode Log Preprocessor Macros
// App specific Logging
#ifdef DEBUG_P
#define PLog(fmt, ...) NSLog((@"%s:%d " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define PLog(fmt, ...) // stubbed out
#endif
// Library specific Logging
#ifdef DEBUG_L
#define LLog(fmt, ...) NSLog((@"%s:%d " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
@albertodebortoli
albertodebortoli / .gitignore
Created March 11, 2012 21:05
.gitignore for Xcode project
.DS_Store
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
xcuserdata/
@albertodebortoli
albertodebortoli / gist:2204433
Created March 26, 2012 10:55
Copy file from bundle to documents directory in iOS
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.filename = @"file.ext";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDir = [documentPaths objectAtIndex:0];
self.filePath = [documentDir stringByAppendingPathComponent:self.filename];
[self createAndCheckDatabase];
@albertodebortoli
albertodebortoli / gist:2306149
Created April 4, 2012 22:29
Abstract Method macro on iOS
#define DEFINE_ABSTRACT_METHOD(returnType, name)\
- (returnType)name {\
@throw [NSException exceptionWithName:NSInternalInconsistencyException\
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]\
userInfo:nil];\
}
// usage
@albertodebortoli
albertodebortoli / .bash_profile
Created May 1, 2012 06:32
export path for Xcode4 toolset
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH
@albertodebortoli
albertodebortoli / gist:2602966
Created May 5, 2012 14:39
JSON to NSManagedObject and viceversa (concept)
- (NSString*)jsonStructureFromManagedObjects:(NSArray*)managedObjects;
- (NSArray*)managedObjectsFromJSONStructure:(NSString*)json withManagedObjectContext:(NSManagedObjectContext*)moc;
- (NSDictionary*)dataStructureFromManagedObject:(NSManagedObject*)managedObject
{
NSDictionary *attributesByName = [[managedObject entity] attributesByName];
NSDictionary *relationshipsByName = [[managedObject entity] relationshipsByName];
NSMutableDictionary *valuesDictionary = [[managedObject dictionaryWithValuesForKeys:[attributesByName allKeys]] mutableCopy];
[valuesDictionary setObject:[[managedObject entity] name] forKey:@"ManagedObjectName"];
for (NSString *relationshipName in [relationshipsByName allKeys]) {
@albertodebortoli
albertodebortoli / gist:2688229
Created May 13, 2012 12:32
check ARC availability
#if __has_feature(objc_arc)
#else
- (void)dealloc
{
[super dealloc];
}
#endif
@albertodebortoli
albertodebortoli / ExampleClass.m
Created June 3, 2012 08:50 — forked from lukeredpath/ExampleClass.m
Macro for creating your "shared instance" using GCD
@implementation MySharedThing
+ (id)sharedInstance
{
DEFINE_SHARED_INSTANCE_USING_BLOCK(^{
return [[self alloc] init];
});
}
@end