Skip to content

Instantly share code, notes, and snippets.

@skrul
Created August 9, 2012 22:50
Show Gist options
  • Save skrul/3308760 to your computer and use it in GitHub Desktop.
Save skrul/3308760 to your computer and use it in GitHub Desktop.
some macros:
#define SGAM_ERROR_MESSAGE(condition, message) \
do { \
if (!(condition)) { \
SGAMError *__error__ = [[SGAMError alloc] initWithMesage:message \
asset:asset_ \
file:__FILE__ \
lineNumber:__LINE__]; \
return [__error__ autorelease]; \
} \
} while (0)
#define SGAM_ERROR_ERROR(condition, err) \
do { \
if (!(condition)) { \
SGAMError *__error__ = [[SGAMError alloc] initWithError:err \
asset:asset_ \
file:__FILE__ \
lineNumber:__LINE__]; \
return [__error__ autorelease]; \
} \
} while (0)
how they are used:
- (SGAMError *)amMain {
SGAM_ERROR_MESSAGE(destination_ && alAsset_ && thumbDestination_,
@"nil argument");
SGAM_CHECK_CANCEL();
// If it exists, remove the file on disk that exists at our destination path.
BOOL exists = [fileManager_ fileExistsAtPath:[destination_ path]];
if (exists) {
NSError *error = NULL;
BOOL success = [fileManager_ removeItemAtURL:destination_ error:&error];
SGAM_ERROR_ERROR(success, error);
}
// Save the full resolution image.
ALAssetRepresentation *rep = [alAsset_ defaultRepresentation];
SGAM_ERROR_MESSAGE(rep, @"nil rep");
CGImageRef img = [rep fullResolutionImage];
SGAM_ERROR_MESSAGE(img, @"nil img");
UIImage *sourceImg =
[UIImage imageWithCGImage:img
scale:rep.scale
orientation:(UIImageOrientation)rep.orientation];
SGAM_ERROR_MESSAGE(sourceImg, @"nil sourceImg");
... etc ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment