Skip to content

Commit 856ea31

Browse files
committed
Validate tracks are actually tracks, init with dict
1 parent 1add14d commit 856ea31

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

TestSwift.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
021E1AEF1944CDDE00FDC37C /* Track.swift in Sources */ = {isa = PBXBuildFile; fileRef = 021E1AEE1944CDDE00FDC37C /* Track.swift */; };
11+
021E1AF11944D4A800FDC37C /* TrackCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 021E1AF01944D4A800FDC37C /* TrackCell.swift */; };
1112
022889EF193FC3AC00D729A0 /* DetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 022889EE193FC3AC00D729A0 /* DetailsViewController.swift */; };
1213
022889F1193FD6C000D729A0 /* Album.swift in Sources */ = {isa = PBXBuildFile; fileRef = 022889F0193FD6C000D729A0 /* Album.swift */; };
1314
0229AE63193F97EF00BCED97 /* Blank52.png in Resources */ = {isa = PBXBuildFile; fileRef = 0229AE62193F97EF00BCED97 /* Blank52.png */; };
@@ -31,6 +32,7 @@
3132

3233
/* Begin PBXFileReference section */
3334
021E1AEE1944CDDE00FDC37C /* Track.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Track.swift; path = Classes/Track.swift; sourceTree = "<group>"; };
35+
021E1AF01944D4A800FDC37C /* TrackCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackCell.swift; sourceTree = "<group>"; };
3436
022889EE193FC3AC00D729A0 /* DetailsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DetailsViewController.swift; path = Classes/DetailsViewController.swift; sourceTree = "<group>"; };
3537
022889F0193FD6C000D729A0 /* Album.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Album.swift; path = Classes/Album.swift; sourceTree = "<group>"; };
3638
0229AE62193F97EF00BCED97 /* Blank52.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Blank52.png; sourceTree = "<group>"; };
@@ -71,6 +73,7 @@
7173
02CCF4A9193D16930069AEE9 /* SearchResultsViewController.swift */,
7274
022889EE193FC3AC00D729A0 /* DetailsViewController.swift */,
7375
02CCF4AB193D16930069AEE9 /* Main.storyboard */,
76+
021E1AF01944D4A800FDC37C /* TrackCell.swift */,
7477
);
7578
name = Views;
7679
sourceTree = "<group>";
@@ -258,6 +261,7 @@
258261
isa = PBXSourcesBuildPhase;
259262
buildActionMask = 2147483647;
260263
files = (
264+
021E1AF11944D4A800FDC37C /* TrackCell.swift in Sources */,
261265
02CCF4AA193D16930069AEE9 /* SearchResultsViewController.swift in Sources */,
262266
02CCF4A8193D16930069AEE9 /* AppDelegate.swift in Sources */,
263267
02F504DB193E0B630037F599 /* APIController.swift in Sources */,

TestSwift/Base.lproj/Main.storyboard

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<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="18C-lM-Kii">
33
<dependencies>
4-
<deployment defaultVersion="1536" identifier="iOS"/>
54
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6153.11"/>
65
</dependencies>
76
<scenes>
@@ -113,7 +112,7 @@
113112
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
114113
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
115114
<prototypes>
116-
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="TrackCell" id="q8P-5k-V04">
115+
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="TrackCell" id="q8P-5k-V04" customClass="TrackCell" customModule="TestSwift" customModuleProvider="target">
117116
<autoresizingMask key="autoresizingMask"/>
118117
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="q8P-5k-V04" id="Hvr-uO-kzf">
119118
<autoresizingMask key="autoresizingMask"/>
@@ -150,13 +149,17 @@
150149
</mask>
151150
</variation>
152151
</tableViewCellContentView>
152+
<connections>
153+
<outlet property="playButton" destination="dE4-MC-wkr" id="h6A-4C-eZj"/>
154+
<outlet property="titleLabel" destination="DPO-xR-L6h" id="Zqj-m2-6gK"/>
155+
</connections>
153156
</tableViewCell>
154157
</prototypes>
155158
<variation key="widthClass=compact" fixedFrame="YES">
156159
<rect key="frame" x="20" y="179" width="280" height="281"/>
157160
</variation>
158161
<variation key="heightClass=regular-widthClass=compact" ambiguous="YES" misplaced="YES">
159-
<rect key="frame" x="20" y="179" width="280" height="461"/>
162+
<rect key="frame" x="0.0" y="179" width="320" height="461"/>
160163
</variation>
161164
<connections>
162165
<outlet property="dataSource" destination="rSr-uw-pic" id="Atq-D3-Xvo"/>

TestSwift/Classes/DetailsViewController.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ class DetailsViewController: UIViewController, UITableViewDelegate, UITableViewD
4040
if let allResults = results["results"] as? NSDictionary[] {
4141
for trackInfo in allResults {
4242
// Create the track
43-
var track = Track(dict: trackInfo)
44-
tracks.append(track)
43+
if let kind = trackInfo["kind"] as? String {
44+
if kind=="song" {
45+
var track = Track(dict: trackInfo)
46+
tracks.append(track)
47+
}
48+
}
4549
}
4650
}
4751
tracksTableView.reloadData()
@@ -53,7 +57,20 @@ class DetailsViewController: UIViewController, UITableViewDelegate, UITableViewD
5357
}
5458

5559
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
56-
return nil
60+
var cell = tableView.dequeueReusableCellWithIdentifier("TrackCell") as TrackCell
61+
62+
var track = tracks[indexPath.row]
63+
cell.titleLabel.text = track.title
64+
65+
/*var playButton = cell.viewWithTag(0) as UIButton
66+
var titleText = cell.viewWithTag(1) as UILabel
67+
68+
var track = tracks[indexPath.row]
69+
70+
titleText.text = track.title
71+
*/
72+
73+
return cell
5774
}
5875

5976
}

TestSwift/Classes/Track.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ class Track {
1212
var price: String?
1313
var previewUrl: String?
1414

15-
init(name: String!, price: String!, previewUrl: String!) {
16-
self.title = name
17-
self.price = price
18-
self.previewUrl = previewUrl
19-
}
20-
2115
init(dict: NSDictionary!) {
22-
16+
self.title = dict["trackName"] as? String
17+
self.price = dict["trackPrice"] as? String
18+
self.previewUrl = dict["previewUrl"] as? String
2319
}
2420

2521
}

TestSwift/TrackCell.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// TrackCell.swift
3+
// TestSwift
4+
//
5+
// Created by Jameson Quave on 6/8/14.
6+
// Copyright (c) 2014 JQ Software LLC. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
12+
class TrackCell: UITableViewCell {
13+
14+
@IBOutlet var playButton: UIButton
15+
@IBOutlet var titleLabel: UILabel
16+
17+
}

0 commit comments

Comments
 (0)