diff --git a/dwyl/dwyl.xcodeproj/project.pbxproj b/dwyl/dwyl.xcodeproj/project.pbxproj index c989059..663ff22 100644 --- a/dwyl/dwyl.xcodeproj/project.pbxproj +++ b/dwyl/dwyl.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 0D2038441E70180C008CB3F4 /* AddTaskViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D2038431E70180C008CB3F4 /* AddTaskViewController.swift */; }; 0D243CD21EAE192700053265 /* materialColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D243CD11EAE192700053265 /* materialColors.swift */; }; 0D24BB911EFC0F8B009D2334 /* dateConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D24BB901EFC0F8B009D2334 /* dateConverter.swift */; }; + 0D24BB961EFC292D009D2334 /* stringToHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D24BB951EFC292D009D2334 /* stringToHash.swift */; }; 0D42F4061EEFFD1D00471321 /* ProjectTimerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D42F4051EEFFD1D00471321 /* ProjectTimerTest.swift */; }; 0D5AA1451E71881E002D87C3 /* TaskCoreData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D5AA1441E71881E002D87C3 /* TaskCoreData.swift */; }; 0D662CE21E70537900AFDE32 /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D662CE11E70537900AFDE32 /* Task.swift */; }; @@ -127,6 +128,8 @@ 0D2038431E70180C008CB3F4 /* AddTaskViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AddTaskViewController.swift; path = ../AddTaskViewController.swift; sourceTree = ""; }; 0D243CD11EAE192700053265 /* materialColors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = materialColors.swift; sourceTree = ""; }; 0D24BB901EFC0F8B009D2334 /* dateConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = dateConverter.swift; sourceTree = ""; }; + 0D24BB941EFC2832009D2334 /* dwyl-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "dwyl-Bridging-Header.h"; sourceTree = ""; }; + 0D24BB951EFC292D009D2334 /* stringToHash.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = stringToHash.swift; sourceTree = ""; }; 0D42F4051EEFFD1D00471321 /* ProjectTimerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProjectTimerTest.swift; sourceTree = ""; }; 0D5AA1441E71881E002D87C3 /* TaskCoreData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskCoreData.swift; sourceTree = ""; }; 0D662CE11E70537900AFDE32 /* Task.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Task.swift; sourceTree = ""; }; @@ -193,6 +196,7 @@ 0D243CD11EAE192700053265 /* materialColors.swift */, 0DB2792C1EC4B2350011559E /* ProjectTimer.swift */, 0D24BB901EFC0F8B009D2334 /* dateConverter.swift */, + 0D24BB951EFC292D009D2334 /* stringToHash.swift */, ); name = lib; sourceTree = ""; @@ -251,6 +255,7 @@ 0D2038141E6D82FD008CB3F4 /* LaunchScreen.storyboard */, 0D2038171E6D82FD008CB3F4 /* Info.plist */, 0D5AA1441E71881E002D87C3 /* TaskCoreData.swift */, + 0D24BB941EFC2832009D2334 /* dwyl-Bridging-Header.h */, ); name = dwyl; path = time; @@ -549,6 +554,7 @@ 0D2038111E6D82FD008CB3F4 /* time.xcdatamodeld in Sources */, 0DB2792D1EC4B2350011559E /* ProjectTimer.swift in Sources */, 0D1D19371E795B6F003C9B39 /* Project+CoreDataClass.swift in Sources */, + 0D24BB961EFC292D009D2334 /* stringToHash.swift in Sources */, 0D24BB911EFC0F8B009D2334 /* dateConverter.swift in Sources */, 0D11C4721E96A15200689D48 /* setNavbarLogo.swift in Sources */, 0D243CD21EAE192700053265 /* materialColors.swift in Sources */, @@ -755,6 +761,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dwyl.time; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "./time/dwyl-Bridging-Header.h"; SWIFT_VERSION = 3.0; }; name = Debug; @@ -775,6 +782,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.dwyl.time; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "./time/dwyl-Bridging-Header.h"; SWIFT_VERSION = 3.0; }; name = Release; diff --git a/dwyl/time/ProjectTimer.swift b/dwyl/time/ProjectTimer.swift index 138e36f..c93d7e1 100644 --- a/dwyl/time/ProjectTimer.swift +++ b/dwyl/time/ProjectTimer.swift @@ -53,7 +53,8 @@ class ProjectTimer { let jsonData = try JSONSerialization.data(withJSONObject: ["project_name": name, "start_date": convertedDate, "isTaskRunning": true], options: .prettyPrinted) let jsonToString = String(data: jsonData, encoding: String.Encoding.utf8) // the data will be converted to the string - print(jsonToString ?? "no data") + let hashedString = StringToHash(jsonToString!) + print(hashedString ?? "no data") } catch { print(error.localizedDescription) diff --git a/dwyl/time/dwyl-Bridging-Header.h b/dwyl/time/dwyl-Bridging-Header.h new file mode 100644 index 0000000..77eb751 --- /dev/null +++ b/dwyl/time/dwyl-Bridging-Header.h @@ -0,0 +1,14 @@ +// +// dwyl-Bridging-Header.h +// dwyl +// +// Created by Sohil Pandya on 22/06/2017. +// Copyright © 2017 dwyl. All rights reserved. +// + +#ifndef dwyl_Bridging_Header_h +#define dwyl_Bridging_Header_h + +#import "CommonCrypto/CommonCrypto.h" + +#endif /* dwyl_Bridging_Header_h */ diff --git a/dwyl/time/stringToHash.swift b/dwyl/time/stringToHash.swift new file mode 100644 index 0000000..d928812 --- /dev/null +++ b/dwyl/time/stringToHash.swift @@ -0,0 +1,24 @@ +// +// stringToHash.swift +// dwyl +// +// Created by Sohil Pandya on 22/06/2017. +// Copyright © 2017 dwyl. All rights reserved. +// + +import Foundation + +func sha256(_ data: Data) -> Data? { + guard let res = NSMutableData(length: Int(CC_SHA256_DIGEST_LENGTH)) else { return nil } + CC_SHA256((data as NSData).bytes, CC_LONG(data.count), res.mutableBytes.assumingMemoryBound(to: UInt8.self)) + return res as Data +} + +func StringToHash(_ str: String) -> String? { + guard + let data = str.data(using: String.Encoding.utf8), + let shaData = sha256(data) + else { return nil } + let rc = shaData.base64EncodedString(options: []) + return rc +}