summaryrefslogtreecommitdiff
path: root/Juick/Helpers
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/Helpers')
-rw-r--r--Juick/Helpers/NSData+Hex.h19
-rw-r--r--Juick/Helpers/NSData+Hex.m22
2 files changed, 41 insertions, 0 deletions
diff --git a/Juick/Helpers/NSData+Hex.h b/Juick/Helpers/NSData+Hex.h
new file mode 100644
index 0000000..bd8e519
--- /dev/null
+++ b/Juick/Helpers/NSData+Hex.h
@@ -0,0 +1,19 @@
+//
+// NSData+Hex.h
+// Juick
+//
+// Created by Vitaly Takmazov on 01/10/2019.
+// Copyright © 2019 com.juick. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface NSData (Hex)
+
+- (NSString *)hexString;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/Juick/Helpers/NSData+Hex.m b/Juick/Helpers/NSData+Hex.m
new file mode 100644
index 0000000..243a380
--- /dev/null
+++ b/Juick/Helpers/NSData+Hex.m
@@ -0,0 +1,22 @@
+//
+// NSData+Hex.m
+// Juick
+//
+// Created by Vitaly Takmazov on 01/10/2019.
+// Copyright © 2019 com.juick. All rights reserved.
+//
+
+#import "NSData+Hex.h"
+
+@implementation NSData (Hex)
+- (NSString *)hexString {
+ NSMutableString *string = [NSMutableString stringWithCapacity:self.length * 3];
+ [self enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop){
+ for (NSUInteger offset = 0; offset < byteRange.length; ++offset) {
+ uint8_t byte = ((const uint8_t *)bytes)[offset];
+ [string appendFormat:@"%02x", byte];
+ }
+ }];
+ return string;
+}
+@end