Created
August 28, 2014 07:02
-
-
Save sgr/d854ab8abe2092773f73 to your computer and use it in GitHub Desktop.
Revisions
-
sgr revised this gist
Aug 29, 2014 . 2 changed files with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ // // NSUUID+Base64.h // // #import <Foundation/Foundation.h> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ // // NSUUID+Base64.m // // #import "NSUUID+Base64.h" -
sgr created this gist
Aug 28, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ // // NSUUID+Base64.h // // Copyright (c) 2014 Shigeru Fujiwara. All rights reserved. // #import <Foundation/Foundation.h> @interface NSUUID (Base64) - (instancetype)initWithBase64String:(NSString*)string withPadding:(BOOL)padding; - (NSString*)Base64StringWithPadding:(BOOL)padding; @end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ // // NSUUID+Base64.m // // Copyright (c) 2014 Shigeru Fujiwara. All rights reserved. // #import "NSUUID+Base64.h" @implementation NSUUID (Base64) - (instancetype)initWithBase64String:(NSString*)string withPadding:(BOOL)padding { if (padding == NO) { string = [string stringByPaddingToLength:(string.length + (string.length % 4)) withString:@"=" startingAtIndex:0]; } NSData* d = [[NSData alloc] initWithBase64EncodedString:string options:NSDataBase64DecodingIgnoreUnknownCharacters]; uuid_t bytes; [d getBytes:bytes]; return [self initWithUUIDBytes:bytes]; } - (NSString*)Base64StringWithPadding:(BOOL)padding { uuid_t bytes; [self getUUIDBytes:bytes]; NSString* string = [[NSData dataWithBytes:bytes length:sizeof(uuid_t)] base64EncodedStringWithOptions:NSDataBase64Encoding76CharacterLineLength]; if (padding == NO) { return [string stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"="]]; } else { return string; } } @end