Created
August 5, 2014 03:42
-
-
Save ks-simakov/c6a81a6dada25d4674d8 to your computer and use it in GitHub Desktop.
Working with NSData as string
This file contains 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 characters
// | |
// NSMutableData+Strings.h | |
// | |
// Created by Konstantin Simakov | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSMutableData (Strings) | |
-(void)appendString:(NSString *)string; | |
-(void)appendFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2); | |
@end |
This file contains 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 characters
// | |
// NSMutableData+Strings.m | |
// | |
// Created by Konstantin Simakov | |
// | |
#import "NSMutableData+Strings.h" | |
@implementation NSMutableData (Strings) | |
-(void)appendString:(NSString *)string | |
{ | |
[self appendData:[string dataUsingEncoding:NSUTF8StringEncoding]]; | |
} | |
-(void)appendFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2) | |
{ | |
va_list al; | |
va_start(al, format); | |
NSString *string = [[NSString alloc] initWithFormat:format arguments:al]; | |
[self appendData:[string dataUsingEncoding:NSUTF8StringEncoding]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment