Skip to content

Commit a37c0a0

Browse files
committed
Part 6
1 parent 049c048 commit a37c0a0

File tree

6 files changed

+216
-36
lines changed

6 files changed

+216
-36
lines changed

SwiftTutorial.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
0256BB63194F3F38003E2942 /* SwiftTutorialTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0256BB62194F3F38003E2942 /* SwiftTutorialTests.swift */; };
1515
0256BB6D194F41F5003E2942 /* APIController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0256BB6C194F41F5003E2942 /* APIController.swift */; };
1616
0256BB6F194F4852003E2942 /* Blank52.png in Resources */ = {isa = PBXBuildFile; fileRef = 0256BB6E194F4852003E2942 /* Blank52.png */; };
17+
0256BB71194F4A9F003E2942 /* Album.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0256BB70194F4A9F003E2942 /* Album.swift */; };
18+
0256BB73194F4B47003E2942 /* DetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0256BB72194F4B47003E2942 /* DetailsViewController.swift */; };
1719
/* End PBXBuildFile section */
1820

1921
/* Begin PBXContainerItemProxy section */
@@ -38,6 +40,8 @@
3840
0256BB62194F3F38003E2942 /* SwiftTutorialTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftTutorialTests.swift; sourceTree = "<group>"; };
3941
0256BB6C194F41F5003E2942 /* APIController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APIController.swift; sourceTree = "<group>"; };
4042
0256BB6E194F4852003E2942 /* Blank52.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Blank52.png; sourceTree = "<group>"; };
43+
0256BB70194F4A9F003E2942 /* Album.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Album.swift; sourceTree = "<group>"; };
44+
0256BB72194F4B47003E2942 /* DetailsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetailsViewController.swift; sourceTree = "<group>"; };
4145
/* End PBXFileReference section */
4246

4347
/* Begin PBXFrameworksBuildPhase section */
@@ -86,6 +90,8 @@
8690
0256BB56194F3F38003E2942 /* Images.xcassets */,
8791
0256BB4D194F3F38003E2942 /* Supporting Files */,
8892
0256BB6C194F41F5003E2942 /* APIController.swift */,
93+
0256BB70194F4A9F003E2942 /* Album.swift */,
94+
0256BB72194F4B47003E2942 /* DetailsViewController.swift */,
8995
);
9096
path = SwiftTutorial;
9197
sourceTree = "<group>";
@@ -218,6 +224,8 @@
218224
0256BB52194F3F38003E2942 /* SearchResultsViewController.swift in Sources */,
219225
0256BB50194F3F38003E2942 /* AppDelegate.swift in Sources */,
220226
0256BB6D194F41F5003E2942 /* APIController.swift in Sources */,
227+
0256BB71194F4A9F003E2942 /* Album.swift in Sources */,
228+
0256BB73194F4B47003E2942 /* DetailsViewController.swift in Sources */,
221229
);
222230
runOnlyForDeploymentPostprocessing = 0;
223231
};

SwiftTutorial/APIController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ protocol APIControllerProtocol {
1515
class APIController: NSObject {
1616
var delegate: APIControllerProtocol?
1717

18+
init(delegate: APIControllerProtocol?) {
19+
self.delegate = delegate
20+
}
21+
1822
func searchItunesFor(searchTerm: String) {
1923

2024
// The iTunes API wants multiple terms separated by + symbols, so replace spaces with + signs
2125
var itunesSearchTerm = searchTerm.stringByReplacingOccurrencesOfString(" ", withString: "+", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil)
2226

2327
// Now escape anything else that isn't URL-friendly
2428
var escapedSearchTerm = itunesSearchTerm.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
25-
var urlPath = "https://itunes.apple.com/search?term=\(escapedSearchTerm)&media=software"
29+
var urlPath = "https://itunes.apple.com/search?term=\(escapedSearchTerm)&media=music&entity=album"
2630
var url: NSURL = NSURL(string: urlPath)
2731
var session = NSURLSession.sharedSession()
2832
var task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in

SwiftTutorial/Album.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Album.swift
3+
// SwiftTutorial
4+
//
5+
// Created by Jameson Quave on 6/16/14.
6+
// Copyright (c) 2014 JQ Software LLC. All rights reserved.
7+
//
8+
9+
class Album {
10+
var title: String?
11+
var price: String?
12+
var thumbnailImageURL: String?
13+
var largeImageURL: String?
14+
var itemURL: String?
15+
var artistURL: String?
16+
17+
init(name: String!, price: String!, thumbnailImageURL: String!, largeImageURL: String!, itemURL: String!, artistURL: String!) {
18+
self.title = name
19+
self.price = price
20+
self.thumbnailImageURL = thumbnailImageURL
21+
self.largeImageURL = largeImageURL
22+
self.itemURL = itemURL
23+
self.artistURL = artistURL
24+
}
25+
}

SwiftTutorial/Base.lproj/Main.storyboard

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
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="vXZ-lx-hvc">
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="gqd-Yd-zOT">
33
<dependencies>
44
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
55
</dependencies>
@@ -45,6 +45,9 @@
4545
</label>
4646
</subviews>
4747
</tableViewCellContentView>
48+
<connections>
49+
<segue destination="xtR-ZP-i6I" kind="show" id="Rhl-hE-TRF"/>
50+
</connections>
4851
</tableViewCell>
4952
</prototypes>
5053
<variation key="heightClass=regular-widthClass=compact" fixedFrame="YES">
@@ -69,12 +72,82 @@
6972
</mask>
7073
</variation>
7174
</view>
75+
<navigationItem key="navigationItem" id="EbB-Vp-8LS"/>
7276
<connections>
7377
<outlet property="appsTableView" destination="0Ds-au-UhU" id="4Ou-lD-tIm"/>
7478
</connections>
7579
</viewController>
7680
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
7781
</objects>
82+
<point key="canvasLocation" x="1026" y="159.75"/>
83+
</scene>
84+
<!--Details View Controller-->
85+
<scene sceneID="uOj-Yq-ktF">
86+
<objects>
87+
<viewController id="xtR-ZP-i6I" customClass="DetailsViewController" customModule="SwiftTutorial" customModuleProvider="target" sceneMemberID="viewController">
88+
<layoutGuides>
89+
<viewControllerLayoutGuide type="top" id="gxh-6G-snX"/>
90+
<viewControllerLayoutGuide type="bottom" id="4A1-t1-Q0W"/>
91+
</layoutGuides>
92+
<view key="view" contentMode="scaleToFill" id="SgI-CA-d2r">
93+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
94+
<subviews>
95+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WgH-O9-qIk">
96+
<rect key="frame" x="0.0" y="-21" width="42" height="21"/>
97+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
98+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
99+
<nil key="highlightedColor"/>
100+
<variation key="heightClass=regular-widthClass=compact" fixedFrame="YES">
101+
<rect key="frame" x="20" y="208" width="280" height="27"/>
102+
</variation>
103+
</label>
104+
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="AIH-2u-9AI">
105+
<rect key="frame" x="0.0" y="0.0" width="240" height="128"/>
106+
<variation key="heightClass=regular-widthClass=compact" fixedFrame="YES">
107+
<rect key="frame" x="110" y="76" width="100" height="100"/>
108+
</variation>
109+
</imageView>
110+
</subviews>
111+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
112+
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
113+
<variation key="default">
114+
<mask key="subviews">
115+
<exclude reference="WgH-O9-qIk"/>
116+
<exclude reference="AIH-2u-9AI"/>
117+
</mask>
118+
</variation>
119+
<variation key="heightClass=regular-widthClass=compact">
120+
<mask key="subviews">
121+
<include reference="WgH-O9-qIk"/>
122+
<include reference="AIH-2u-9AI"/>
123+
</mask>
124+
</variation>
125+
</view>
126+
<connections>
127+
<outlet property="albumCover" destination="AIH-2u-9AI" id="8jE-Og-JYE"/>
128+
<outlet property="titleLabel" destination="WgH-O9-qIk" id="dRW-M7-mY6"/>
129+
</connections>
130+
</viewController>
131+
<placeholder placeholderIdentifier="IBFirstResponder" id="rhu-ce-V5h" userLabel="First Responder" sceneMemberID="firstResponder"/>
132+
</objects>
133+
<point key="canvasLocation" x="1593" y="159.75"/>
134+
</scene>
135+
<!--Navigation Controller-->
136+
<scene sceneID="3Xq-0n-iKS">
137+
<objects>
138+
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="gqd-Yd-zOT" sceneMemberID="viewController">
139+
<toolbarItems/>
140+
<navigationBar key="navigationBar" contentMode="scaleToFill" id="kYD-59-bHB">
141+
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
142+
<autoresizingMask key="autoresizingMask"/>
143+
</navigationBar>
144+
<nil name="viewControllers"/>
145+
<connections>
146+
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="rootViewController" id="Wgx-qf-4fF"/>
147+
</connections>
148+
</navigationController>
149+
<placeholder placeholderIdentifier="IBFirstResponder" id="zYz-z3-Hj9" userLabel="First Responder" sceneMemberID="firstResponder"/>
150+
</objects>
78151
<point key="canvasLocation" x="228" y="159.75"/>
79152
</scene>
80153
</scenes>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// DetailsViewController.swift
3+
// SwiftTutorial
4+
//
5+
// Created by Jameson Quave on 6/16/14.
6+
// Copyright (c) 2014 JQ Software LLC. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class DetailsViewController: UIViewController {
12+
13+
@IBOutlet var albumCover : UIImageView
14+
@IBOutlet var titleLabel : UILabel
15+
16+
var album: Album?
17+
18+
init(coder aDecoder: NSCoder!) {
19+
super.init(coder: aDecoder)
20+
}
21+
22+
override func viewDidLoad() {
23+
super.viewDidLoad()
24+
titleLabel.text = self.album?.title
25+
albumCover.image = UIImage(data: NSData(contentsOfURL: NSURL(string: self.album?.largeImageURL)))
26+
}
27+
}

0 commit comments

Comments
 (0)