Skip to content

Commit e2ae686

Browse files
committed
Part 3
1 parent 4f19d6f commit e2ae686

File tree

11 files changed

+291
-34
lines changed

11 files changed

+291
-34
lines changed

TestSwift.xcodeproj/project.pbxproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
026336BE193D3BB300765E31 /* Icon76.png in Resources */ = {isa = PBXBuildFile; fileRef = 026336BD193D3BB300765E31 /* Icon76.png */; };
1011
02CCF4A8193D16930069AEE9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02CCF4A7193D16930069AEE9 /* AppDelegate.swift */; };
11-
02CCF4AA193D16930069AEE9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02CCF4A9193D16930069AEE9 /* ViewController.swift */; };
12+
02CCF4AA193D16930069AEE9 /* SearchResultsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02CCF4A9193D16930069AEE9 /* SearchResultsViewController.swift */; };
1213
02CCF4AD193D16930069AEE9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 02CCF4AB193D16930069AEE9 /* Main.storyboard */; };
1314
02CCF4AF193D16930069AEE9 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 02CCF4AE193D16930069AEE9 /* Images.xcassets */; };
1415
02CCF4BB193D16930069AEE9 /* TestSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02CCF4BA193D16930069AEE9 /* TestSwiftTests.swift */; };
16+
02F504DB193E0B630037F599 /* APIController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02F504DA193E0B630037F599 /* APIController.swift */; };
1517
/* End PBXBuildFile section */
1618

1719
/* Begin PBXContainerItemProxy section */
@@ -25,15 +27,17 @@
2527
/* End PBXContainerItemProxy section */
2628

2729
/* Begin PBXFileReference section */
30+
026336BD193D3BB300765E31 /* Icon76.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon76.png; sourceTree = "<group>"; };
2831
02CCF4A2193D16930069AEE9 /* TestSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestSwift.app; sourceTree = BUILT_PRODUCTS_DIR; };
2932
02CCF4A6193D16930069AEE9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3033
02CCF4A7193D16930069AEE9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
31-
02CCF4A9193D16930069AEE9 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
34+
02CCF4A9193D16930069AEE9 /* SearchResultsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultsViewController.swift; sourceTree = "<group>"; };
3235
02CCF4AC193D16930069AEE9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
3336
02CCF4AE193D16930069AEE9 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
3437
02CCF4B4193D16930069AEE9 /* TestSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3538
02CCF4B9193D16930069AEE9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3639
02CCF4BA193D16930069AEE9 /* TestSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSwiftTests.swift; sourceTree = "<group>"; };
40+
02F504DA193E0B630037F599 /* APIController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APIController.swift; sourceTree = "<group>"; };
3741
/* End PBXFileReference section */
3842

3943
/* Begin PBXFrameworksBuildPhase section */
@@ -75,8 +79,10 @@
7579
02CCF4A4193D16930069AEE9 /* TestSwift */ = {
7680
isa = PBXGroup;
7781
children = (
82+
026336BD193D3BB300765E31 /* Icon76.png */,
7883
02CCF4A7193D16930069AEE9 /* AppDelegate.swift */,
79-
02CCF4A9193D16930069AEE9 /* ViewController.swift */,
84+
02CCF4A9193D16930069AEE9 /* SearchResultsViewController.swift */,
85+
02F504DA193E0B630037F599 /* APIController.swift */,
8086
02CCF4AB193D16930069AEE9 /* Main.storyboard */,
8187
02CCF4AE193D16930069AEE9 /* Images.xcassets */,
8288
02CCF4A5193D16930069AEE9 /* Supporting Files */,
@@ -191,6 +197,7 @@
191197
files = (
192198
02CCF4AD193D16930069AEE9 /* Main.storyboard in Resources */,
193199
02CCF4AF193D16930069AEE9 /* Images.xcassets in Resources */,
200+
026336BE193D3BB300765E31 /* Icon76.png in Resources */,
194201
);
195202
runOnlyForDeploymentPostprocessing = 0;
196203
};
@@ -208,8 +215,9 @@
208215
isa = PBXSourcesBuildPhase;
209216
buildActionMask = 2147483647;
210217
files = (
211-
02CCF4AA193D16930069AEE9 /* ViewController.swift in Sources */,
218+
02CCF4AA193D16930069AEE9 /* SearchResultsViewController.swift in Sources */,
212219
02CCF4A8193D16930069AEE9 /* AppDelegate.swift in Sources */,
220+
02F504DB193E0B630037F599 /* APIController.swift in Sources */,
213221
);
214222
runOnlyForDeploymentPostprocessing = 0;
215223
};
@@ -399,6 +407,7 @@
399407
02CCF4C0193D16930069AEE9 /* Release */,
400408
);
401409
defaultConfigurationIsVisible = 0;
410+
defaultConfigurationName = Release;
402411
};
403412
02CCF4C1193D16930069AEE9 /* Build configuration list for PBXNativeTarget "TestSwiftTests" */ = {
404413
isa = XCConfigurationList;
@@ -407,6 +416,7 @@
407416
02CCF4C3193D16930069AEE9 /* Release */,
408417
);
409418
defaultConfigurationIsVisible = 0;
419+
defaultConfigurationName = Release;
410420
};
411421
/* End XCConfigurationList section */
412422
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "2.0">
5+
</Bucket>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0600"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "02CCF4A1193D16930069AEE9"
18+
BuildableName = "TestSwift.app"
19+
BlueprintName = "TestSwift"
20+
ReferencedContainer = "container:TestSwift.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "02CCF4B3193D16930069AEE9"
36+
BuildableName = "TestSwiftTests.xctest"
37+
BlueprintName = "TestSwiftTests"
38+
ReferencedContainer = "container:TestSwift.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "02CCF4A1193D16930069AEE9"
46+
BuildableName = "TestSwift.app"
47+
BlueprintName = "TestSwift"
48+
ReferencedContainer = "container:TestSwift.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
51+
</TestAction>
52+
<LaunchAction
53+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
54+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
55+
launchStyle = "0"
56+
useCustomWorkingDirectory = "NO"
57+
buildConfiguration = "Debug"
58+
ignoresPersistentStateOnLaunch = "NO"
59+
debugDocumentVersioning = "YES"
60+
allowLocationSimulation = "YES">
61+
<BuildableProductRunnable>
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "02CCF4A1193D16930069AEE9"
65+
BuildableName = "TestSwift.app"
66+
BlueprintName = "TestSwift"
67+
ReferencedContainer = "container:TestSwift.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
<AdditionalOptions>
71+
</AdditionalOptions>
72+
</LaunchAction>
73+
<ProfileAction
74+
shouldUseLaunchSchemeArgsEnv = "YES"
75+
savedToolIdentifier = ""
76+
useCustomWorkingDirectory = "NO"
77+
buildConfiguration = "Release"
78+
debugDocumentVersioning = "YES">
79+
<BuildableProductRunnable>
80+
<BuildableReference
81+
BuildableIdentifier = "primary"
82+
BlueprintIdentifier = "02CCF4A1193D16930069AEE9"
83+
BuildableName = "TestSwift.app"
84+
BlueprintName = "TestSwift"
85+
ReferencedContainer = "container:TestSwift.xcodeproj">
86+
</BuildableReference>
87+
</BuildableProductRunnable>
88+
</ProfileAction>
89+
<AnalyzeAction
90+
buildConfiguration = "Debug">
91+
</AnalyzeAction>
92+
<ArchiveAction
93+
buildConfiguration = "Release"
94+
revealArchiveInOrganizer = "YES">
95+
</ArchiveAction>
96+
</Scheme>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>TestSwift.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>02CCF4A1193D16930069AEE9</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
<key>02CCF4B3193D16930069AEE9</key>
21+
<dict>
22+
<key>primary</key>
23+
<true/>
24+
</dict>
25+
</dict>
26+
</dict>
27+
</plist>

TestSwift/APIController.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// APIController.swift
3+
// TestSwift
4+
//
5+
// Created by Jameson Quave on 6/3/14.
6+
// Copyright (c) 2014 JQ Software LLC. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
protocol APIControllerProtocol {
12+
func didRecieveAPIResults(results: NSDictionary)
13+
}
14+
15+
class APIController: NSObject {
16+
17+
var data: NSMutableData = NSMutableData()
18+
var delegate: APIControllerProtocol?
19+
20+
func searchItunesFor(searchTerm: String) {
21+
22+
// The iTunes API wants multiple terms separated by + symbols, so replace spaces with + signs
23+
var itunesSearchTerm = searchTerm.stringByReplacingOccurrencesOfString(" ", withString: "+", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil)
24+
25+
// Now escape anything else that isn't URL-friendly
26+
var escapedSearchTerm = itunesSearchTerm.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
27+
var urlPath = "https://itunes.apple.com/search?term=\(escapedSearchTerm)&media=software"
28+
var url: NSURL = NSURL(string: urlPath)
29+
var request: NSURLRequest = NSURLRequest(URL: url)
30+
var connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: false)
31+
32+
connection.start()
33+
}
34+
35+
36+
func connection(connection: NSURLConnection!, didFailWithError error: NSError!) {
37+
println("Connection failed.\(error.localizedDescription)")
38+
}
39+
40+
41+
func connection(didReceiveResponse: NSURLConnection!, didReceiveResponse response: NSURLResponse!) {
42+
// Recieved a new request, clear out the data object
43+
self.data = NSMutableData()
44+
}
45+
46+
func connection(connection: NSURLConnection!, didReceiveData data: NSData!) {
47+
// Append the recieved chunk of data to our data object
48+
self.data.appendData(data)
49+
}
50+
51+
func connectionDidFinishLoading(connection: NSURLConnection!) {
52+
// Request complete, self.data should now hold the resulting info
53+
// Convert the retrieved data in to an object through JSON deserialization
54+
var err: NSError
55+
var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
56+
57+
// Now send the JSON result to our delegate object
58+
delegate?.didRecieveAPIResults(jsonResult)
59+
}
60+
61+
62+
}

TestSwift/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1515

1616

1717
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
18-
// Override point for customization after application launch.
18+
1919
return true
2020
}
2121

TestSwift/Base.lproj/Main.storyboard

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6162" systemVersion="14A238h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6154.17" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6160"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
55
</dependencies>
66
<scenes>
7-
<!--View Controller-->
7+
<!--Search Results View Controller-->
88
<scene sceneID="tne-QT-ifu">
99
<objects>
10-
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
10+
<viewController id="BYZ-38-t0r" customClass="SearchResultsViewController" customModule="TestSwift" customModuleProvider="target" sceneMemberID="viewController">
1111
<layoutGuides>
1212
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
1313
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
1414
</layoutGuides>
1515
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1616
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
1717
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+
<subviews>
19+
<tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="jTM-Fb-meD">
20+
<rect key="frame" x="0.0" y="37" width="480" height="443"/>
21+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
22+
<connections>
23+
<outlet property="dataSource" destination="BYZ-38-t0r" id="Rph-up-PTP"/>
24+
<outlet property="delegate" destination="BYZ-38-t0r" id="zEB-7D-wXK"/>
25+
</connections>
26+
</tableView>
27+
</subviews>
1828
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
29+
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
1930
</view>
31+
<connections>
32+
<outlet property="appsTableView" destination="jTM-Fb-meD" id="NN5-oX-ovP"/>
33+
</connections>
2034
</viewController>
2135
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
2236
</objects>
37+
<point key="canvasLocation" x="303" y="254"/>
2338
</scene>
2439
</scenes>
2540
</document>

TestSwift/Icon76.png

7.73 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Timeline
3+
version = "3.0">
4+
<TimelineItems>
5+
</TimelineItems>
6+
</Timeline>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// ViewController.swift
3+
// TestSwift
4+
//
5+
// Created by Jameson Quave on 6/2/14.
6+
// Copyright (c) 2014 JQ Software LLC. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class SearchResultsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, APIControllerProtocol {
12+
13+
var api: APIController = APIController()
14+
@IBOutlet var appsTableView : UITableView
15+
var tableData: NSArray = NSArray()
16+
17+
override func viewDidLoad() {
18+
super.viewDidLoad()
19+
api.delegate = self
20+
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
21+
api.searchItunesFor("Angry Birds");
22+
}
23+
24+
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
25+
return tableData.count
26+
}
27+
28+
29+
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
30+
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")
31+
32+
var rowData: NSDictionary = self.tableData[indexPath.row] as NSDictionary
33+
34+
cell.text = rowData["trackName"] as String
35+
36+
// Grab the artworkUrl60 key to get an image URL for the app's thumbnail
37+
var urlString: NSString = rowData["artworkUrl60"] as NSString
38+
var imgURL: NSURL = NSURL(string: urlString)
39+
40+
// Download an NSData representation of the image at the URL
41+
var imgData: NSData = NSData(contentsOfURL: imgURL)
42+
cell.image = UIImage(data: imgData)
43+
44+
// Get the formatted price string for display in the subtitle
45+
var formattedPrice: NSString = rowData["formattedPrice"] as NSString
46+
47+
cell.detailTextLabel.text = formattedPrice
48+
49+
return cell
50+
}
51+
52+
func didRecieveAPIResults(results: NSDictionary) {
53+
// Store the results in our table data array
54+
if results.count>0 {
55+
self.tableData = results["results"] as NSArray
56+
self.appsTableView.reloadData()
57+
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
58+
}
59+
}
60+
61+
}

0 commit comments

Comments
 (0)