Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions VaultCodeTest/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,66 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="KHX-dg-iEW">
<rect key="frame" x="16" y="20" width="343" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="KHX-dg-iEW">
<rect key="frame" x="16" y="45" width="343" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="TMS-n5-Z2z"/>
</constraints>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="6a8-QR-JdA">
<rect key="frame" x="16" y="92" width="343" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="6a8-QR-JdA">
<rect key="frame" x="16" y="117" width="343" height="30"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="K2H-H9-Kdq">
<rect key="frame" x="132" y="130" width="111" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="K2H-H9-Kdq">
<rect key="frame" x="132" y="155" width="111" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="0hP-Xx-tdt"/>
<constraint firstAttribute="width" constant="111" id="msk-Hy-fH1"/>
</constraints>
<state key="normal" title="Load Image"/>
<connections>
<action selector="getCat" destination="BYZ-38-t0r" eventType="touchUpInside" id="xyg-ZF-Ktr"/>
</connections>
</button>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="YKv-D3-Q5U">
<rect key="frame" x="67" y="168" width="240" height="128"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="YKv-D3-Q5U">
<rect key="frame" x="0.0" y="190" width="375" height="477"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fJH-t1-BHU">
<rect key="frame" x="132" y="54" width="111" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fJH-t1-BHU">
<rect key="frame" x="132" y="79" width="111" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="3rH-Jr-Lia"/>
<constraint firstAttribute="width" constant="111" id="QV8-9Q-aGA"/>
</constraints>
<state key="normal" title="Reverse String"/>
<connections>
<action selector="processString:" destination="BYZ-38-t0r" eventType="touchDown" id="J31-UV-oC1"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="KHX-dg-iEW" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="25" id="4wY-C8-MTL"/>
<constraint firstItem="YKv-D3-Q5U" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="170" id="7tP-g9-Kea"/>
<constraint firstItem="fJH-t1-BHU" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="IJl-bZ-ToT"/>
<constraint firstItem="KHX-dg-iEW" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="IXQ-YP-c6t"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="KHX-dg-iEW" secondAttribute="trailing" constant="16" id="KKQ-YO-Nh0"/>
<constraint firstItem="6a8-QR-JdA" firstAttribute="top" secondItem="fJH-t1-BHU" secondAttribute="bottom" constant="8" id="KYh-tr-tgD"/>
<constraint firstItem="K2H-H9-Kdq" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="N6W-89-ldc"/>
<constraint firstItem="6a8-QR-JdA" firstAttribute="trailing" secondItem="KHX-dg-iEW" secondAttribute="trailing" id="Ua9-6A-1Xi"/>
<constraint firstItem="6a8-QR-JdA" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="WTB-9N-kgk"/>
<constraint firstItem="YKv-D3-Q5U" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="ZXf-Hn-At3"/>
<constraint firstItem="KHX-dg-iEW" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="li0-FS-lRB"/>
<constraint firstItem="YKv-D3-Q5U" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="myE-0r-08f"/>
<constraint firstItem="6a8-QR-JdA" firstAttribute="leading" secondItem="KHX-dg-iEW" secondAttribute="leading" id="pZF-5d-jSP"/>
<constraint firstItem="K2H-H9-Kdq" firstAttribute="top" secondItem="6a8-QR-JdA" secondAttribute="bottom" constant="8" id="sgv-iR-8c5"/>
<constraint firstItem="fJH-t1-BHU" firstAttribute="top" secondItem="KHX-dg-iEW" secondAttribute="bottom" constant="4" id="xak-fm-B5X"/>
<constraint firstItem="YKv-D3-Q5U" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="z6F-so-YwF"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
Expand All @@ -65,3 +92,4 @@
</scene>
</scenes>
</document>

6 changes: 6 additions & 0 deletions VaultCodeTest/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>

9 changes: 9 additions & 0 deletions VaultCodeTest/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@


- (IBAction)processString:(id)sender;
- (IBAction)getCat;
- (NSString *)reverseString:(NSString *)string;

@property (weak, nonatomic) IBOutlet UITextField *textSrc;
@property (weak, nonatomic) IBOutlet UITextField *textDest;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageViewBottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageViewLeadingConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageViewTrailingConstraint;


@end


38 changes: 38 additions & 0 deletions VaultCodeTest/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
//

#import "ViewController.h"
#import <AFNetworking/AFNetworking.h>
#import "AFImageDownloader.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize textSrc, textDest, imageView;

- (void)viewDidLoad {
[super viewDidLoad];
Expand All @@ -27,5 +30,40 @@ - (void)didReceiveMemoryWarning {

- (IBAction)processString:(id)sender {
// Reverse string in textSrc and assign to textDest here
textDest.text = [self reverseString:textSrc.text];
}

- (IBAction)getCat {
NSDate *now = [NSDate date];
NSString *catImageStr = [NSString stringWithFormat:@"http://thecatapi.com/api/images/get?format=src&type=gif&timeindex=%f", now.timeIntervalSince1970]; // providing a time index ensures we get a new kitty each time the button is pressed, not one from a cached request.

AFImageDownloader *downloader = [AFImageDownloader defaultInstance];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: catImageStr]];

[downloader downloadImageForURLRequest:request success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull responseObject) {
[imageView setImage:responseObject];

} failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {
[self alertForCatDownloadError];
}];
}

- (NSString *)reverseString:(NSString *)string {
NSMutableString *reversedText = [[NSMutableString alloc] initWithCapacity:string.length];
for (NSInteger i = string.length - 1; i > -1; i--) {
[reversedText appendString:[string substringWithRange:NSMakeRange(i, 1)]];
}
return reversedText;
}

- (void)alertForCatDownloadError {
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Problem getting kitty" message:@"Sorry, we were unable to retrieve a kitty from thecatapi.com site. Please try again in a moment." preferredStyle:UIAlertControllerStyleAlert];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];
[self presentViewController:actionSheet animated:YES completion:nil];
}

@end

5 changes: 4 additions & 1 deletion VaultCodeTestTests/VaultCodeTestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ - (void)testReverseString {
NSString *src = @"abc123";
NSString *result = @"321cba";

NSString *test = @""; // Assign result of string reversal function here
ViewController *controller = [ViewController new];

NSString *test = [controller reverseString:src]; // Assign result of string reversal function here

XCTAssertTrue([result isEqualToString:test]);
}

@end