From 4258a1e5413eeb22b634f3574ffd565da25b2807 Mon Sep 17 00:00:00 2001 From: Michael Steele Date: Tue, 17 Apr 2018 14:54:21 -0600 Subject: [PATCH 1/2] Added code for reverse string and load image / placement. --- VaultCodeTest.xcodeproj/project.pbxproj | 64 ------------------------ VaultCodeTest/Base.lproj/Main.storyboard | 12 +++-- VaultCodeTest/ViewController.h | 1 + VaultCodeTest/ViewController.m | 32 +++++++++++- 4 files changed, 40 insertions(+), 69 deletions(-) diff --git a/VaultCodeTest.xcodeproj/project.pbxproj b/VaultCodeTest.xcodeproj/project.pbxproj index d22cb0a..7621e00 100644 --- a/VaultCodeTest.xcodeproj/project.pbxproj +++ b/VaultCodeTest.xcodeproj/project.pbxproj @@ -175,8 +175,6 @@ E1F67E062073D43B00DB272D /* Sources */, E1F67E072073D43B00DB272D /* Frameworks */, E1F67E082073D43B00DB272D /* Resources */, - 6FE68FF0FE47869B1519C47A /* [CP] Embed Pods Frameworks */, - 09E4CF660F01B99F0FBB01FD /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -195,8 +193,6 @@ E1F67E1E2073D43B00DB272D /* Sources */, E1F67E1F2073D43B00DB272D /* Frameworks */, E1F67E202073D43B00DB272D /* Resources */, - 9044756752E26EEC25B06432 /* [CP] Embed Pods Frameworks */, - FDC085E49CCF080A17244F77 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -299,21 +295,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 09E4CF660F01B99F0FBB01FD /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-VaultCodeTest/Pods-VaultCodeTest-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; 3F42EDF1754853F6B0E04A1F /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -332,36 +313,6 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 6FE68FF0FE47869B1519C47A /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-VaultCodeTest/Pods-VaultCodeTest-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - 9044756752E26EEC25B06432 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-VaultCodeTestTests/Pods-VaultCodeTestTests-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; B82348C9036591DF23B53339 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -380,21 +331,6 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - FDC085E49CCF080A17244F77 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-VaultCodeTestTests/Pods-VaultCodeTestTests-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/VaultCodeTest/Base.lproj/Main.storyboard b/VaultCodeTest/Base.lproj/Main.storyboard index 1709965..fb2a605 100644 --- a/VaultCodeTest/Base.lproj/Main.storyboard +++ b/VaultCodeTest/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -36,8 +36,11 @@ + + + - + @@ -46,7 +49,7 @@ - + @@ -55,6 +58,7 @@ + diff --git a/VaultCodeTest/ViewController.h b/VaultCodeTest/ViewController.h index f06a99d..e15b9a6 100644 --- a/VaultCodeTest/ViewController.h +++ b/VaultCodeTest/ViewController.h @@ -15,6 +15,7 @@ @property (weak, nonatomic) IBOutlet UITextField *textSrc; @property (weak, nonatomic) IBOutlet UITextField *textDest; @property (weak, nonatomic) IBOutlet UIImageView *imageView; +@property (weak, nonatomic) IBOutlet UIButton *loadImageButton; @end diff --git a/VaultCodeTest/ViewController.m b/VaultCodeTest/ViewController.m index e2fc0be..22360a0 100644 --- a/VaultCodeTest/ViewController.m +++ b/VaultCodeTest/ViewController.m @@ -7,9 +7,10 @@ // #import "ViewController.h" +#import +#import @interface ViewController () - @end @implementation ViewController @@ -27,5 +28,34 @@ - (void)didReceiveMemoryWarning { - (IBAction)processString:(id)sender { // Reverse string in textSrc and assign to textDest here + + NSMutableString *textReversedString = [[NSMutableString alloc] init]; + + [[_textSrc text] enumerateSubstringsInRange:NSMakeRange(0,[[_textSrc text] length]) + options:(NSStringEnumerationReverse | NSStringEnumerationByComposedCharacterSequences) + usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { + [textReversedString appendString:substring]; + }]; + + [_textDest setText:textReversedString]; +} + +- (IBAction)loadImageAction:(id)sender { + + AFImageDownloader* imageDownloader = [[AFImageDownloader alloc] init]; + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: @"https://thecatapi.com/api/images/get?format=src&type=png"]]; + + [imageDownloader downloadImageForURLRequest:request success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull responseObject) { + NSLog(@"Success: Image downloaded."); + CGRect lastFrame = [_loadImageButton frame]; + CGRect viewFrame = [[self view] frame]; + CGFloat offset = lastFrame.size.height; + CGRect imageFrame = CGRectMake(viewFrame.origin.x, lastFrame.origin.y + offset, viewFrame.size.width, viewFrame.size.height - lastFrame.origin.y - offset); + [_imageView setFrame: imageFrame]; + [_imageView setImage: responseObject]; + + } failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) { + NSLog(@"Failed to download image."); + }]; } @end From 69d39c60245bd7beec871523e0cdaceaf3d5d3dd Mon Sep 17 00:00:00 2001 From: Michael Steele Date: Tue, 17 Apr 2018 15:45:22 -0600 Subject: [PATCH 2/2] Added working unit test. --- VaultCodeTest.xcodeproj/project.pbxproj | 6 ++++++ VaultCodeTest/Extensions/NSString+Remove.h | 13 ++++++++++++ VaultCodeTest/Extensions/NSString+Remove.m | 23 ++++++++++++++++++++++ VaultCodeTest/ViewController.m | 11 ++--------- VaultCodeTestTests/VaultCodeTestTests.m | 3 ++- 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 VaultCodeTest/Extensions/NSString+Remove.h create mode 100644 VaultCodeTest/Extensions/NSString+Remove.m diff --git a/VaultCodeTest.xcodeproj/project.pbxproj b/VaultCodeTest.xcodeproj/project.pbxproj index 7621e00..45925ba 100644 --- a/VaultCodeTest.xcodeproj/project.pbxproj +++ b/VaultCodeTest.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 11BB01302086A0CE0073C1D1 /* NSString+Remove.m in Sources */ = {isa = PBXBuildFile; fileRef = 11BB012F2086A0CE0073C1D1 /* NSString+Remove.m */; }; 7F5A90D2C4103D3206133DB0 /* libPods-VaultCodeTestTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E2A89628BEAD9BA5B75ABD1B /* libPods-VaultCodeTestTests.a */; }; E1F67E0F2073D43B00DB272D /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E1F67E0E2073D43B00DB272D /* AppDelegate.m */; }; E1F67E122073D43B00DB272D /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E1F67E112073D43B00DB272D /* ViewController.m */; }; @@ -39,6 +40,8 @@ /* Begin PBXFileReference section */ 064B29C7A8542B1A25225FC4 /* Pods-VaultCodeTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VaultCodeTest.debug.xcconfig"; path = "Pods/Target Support Files/Pods-VaultCodeTest/Pods-VaultCodeTest.debug.xcconfig"; sourceTree = ""; }; 0F93E4D7F0DF9446E8F1335A /* Pods-VaultCodeTestTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VaultCodeTestTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-VaultCodeTestTests/Pods-VaultCodeTestTests.debug.xcconfig"; sourceTree = ""; }; + 11BB012E2086A0CE0073C1D1 /* NSString+Remove.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "NSString+Remove.h"; path = "Extensions/NSString+Remove.h"; sourceTree = ""; }; + 11BB012F2086A0CE0073C1D1 /* NSString+Remove.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "NSString+Remove.m"; path = "Extensions/NSString+Remove.m"; sourceTree = ""; }; 213FE0C287ACBAD6BABFD745 /* Pods-VaultCodeTest.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VaultCodeTest.release.xcconfig"; path = "Pods/Target Support Files/Pods-VaultCodeTest/Pods-VaultCodeTest.release.xcconfig"; sourceTree = ""; }; 62A2E7A33FF0E66DCF6E23E6 /* libPods-VaultCodeTest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VaultCodeTest.a"; sourceTree = BUILT_PRODUCTS_DIR; }; E1F67E0A2073D43B00DB272D /* VaultCodeTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VaultCodeTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -137,6 +140,8 @@ E1F67E0E2073D43B00DB272D /* AppDelegate.m */, E1F67E102073D43B00DB272D /* ViewController.h */, E1F67E112073D43B00DB272D /* ViewController.m */, + 11BB012E2086A0CE0073C1D1 /* NSString+Remove.h */, + 11BB012F2086A0CE0073C1D1 /* NSString+Remove.m */, E1F67E132073D43B00DB272D /* Main.storyboard */, E1F67E162073D43B00DB272D /* Assets.xcassets */, E1F67E182073D43B00DB272D /* LaunchScreen.storyboard */, @@ -339,6 +344,7 @@ buildActionMask = 2147483647; files = ( E1F67E122073D43B00DB272D /* ViewController.m in Sources */, + 11BB01302086A0CE0073C1D1 /* NSString+Remove.m in Sources */, E1F67E1D2073D43B00DB272D /* main.m in Sources */, E1F67E0F2073D43B00DB272D /* AppDelegate.m in Sources */, ); diff --git a/VaultCodeTest/Extensions/NSString+Remove.h b/VaultCodeTest/Extensions/NSString+Remove.h new file mode 100644 index 0000000..d09e35c --- /dev/null +++ b/VaultCodeTest/Extensions/NSString+Remove.h @@ -0,0 +1,13 @@ +// +// NSString+NSString_Remove.h +// VaultCodeTest +// +// Created by Michael Steele on 4/17/18. +// Copyright © 2018 Vault. All rights reserved. +// + +#import + +@interface NSString (Remove) +-(NSString *)reverse; +@end diff --git a/VaultCodeTest/Extensions/NSString+Remove.m b/VaultCodeTest/Extensions/NSString+Remove.m new file mode 100644 index 0000000..27356d2 --- /dev/null +++ b/VaultCodeTest/Extensions/NSString+Remove.m @@ -0,0 +1,23 @@ +// +// NSString+NSString_Remove.m +// VaultCodeTest +// +// Created by Michael Steele on 4/17/18. +// Copyright © 2018 Vault. All rights reserved. +// + +#import "NSString+Remove.h" + +@implementation NSString (Remove) + +-(NSString *)reverse { + NSMutableString *textReversedString = [[NSMutableString alloc] init]; + + [self enumerateSubstringsInRange:NSMakeRange(0,[self length]) + options:(NSStringEnumerationReverse | NSStringEnumerationByComposedCharacterSequences) + usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { + [textReversedString appendString:substring]; + }]; + return textReversedString; +} +@end diff --git a/VaultCodeTest/ViewController.m b/VaultCodeTest/ViewController.m index 22360a0..1c1c253 100644 --- a/VaultCodeTest/ViewController.m +++ b/VaultCodeTest/ViewController.m @@ -9,6 +9,7 @@ #import "ViewController.h" #import #import +#import "NSString+Remove.h" @interface ViewController () @end @@ -29,15 +30,7 @@ - (void)didReceiveMemoryWarning { - (IBAction)processString:(id)sender { // Reverse string in textSrc and assign to textDest here - NSMutableString *textReversedString = [[NSMutableString alloc] init]; - - [[_textSrc text] enumerateSubstringsInRange:NSMakeRange(0,[[_textSrc text] length]) - options:(NSStringEnumerationReverse | NSStringEnumerationByComposedCharacterSequences) - usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { - [textReversedString appendString:substring]; - }]; - - [_textDest setText:textReversedString]; + [_textDest setText:[[_textSrc text] reverse]]; } - (IBAction)loadImageAction:(id)sender { diff --git a/VaultCodeTestTests/VaultCodeTestTests.m b/VaultCodeTestTests/VaultCodeTestTests.m index 2dcd33b..5ff235c 100644 --- a/VaultCodeTestTests/VaultCodeTestTests.m +++ b/VaultCodeTestTests/VaultCodeTestTests.m @@ -8,6 +8,7 @@ #import #import "ViewController.h" +#import "NSString+Remove.h" @interface VaultCodeTestTests : XCTestCase @@ -27,7 +28,7 @@ - (void)testReverseString { NSString *src = @"abc123"; NSString *result = @"321cba"; - NSString *test = @""; // Assign result of string reversal function here + NSString *test = [src reverse]; // Assign result of string reversal function here XCTAssertTrue([result isEqualToString:test]); }