Skip to content

Commit caf67fa

Browse files
committed
Type inference + Bridging header
1 parent fa35f4e commit caf67fa

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

TestSwift.xcodeproj/project.pbxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
022889EE193FC3AC00D729A0 /* DetailsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DetailsViewController.swift; path = Classes/DetailsViewController.swift; sourceTree = "<group>"; };
3333
022889F0193FD6C000D729A0 /* Album.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Album.swift; path = Classes/Album.swift; sourceTree = "<group>"; };
3434
0229AE62193F97EF00BCED97 /* Blank52.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Blank52.png; sourceTree = "<group>"; };
35+
028D579A1944A6C300268B8F /* TestSwift-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TestSwift-Bridging-Header.h"; sourceTree = "<group>"; };
3536
02CCF4A2193D16930069AEE9 /* TestSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestSwift.app; sourceTree = BUILT_PRODUCTS_DIR; };
3637
02CCF4A6193D16930069AEE9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3738
02CCF4A7193D16930069AEE9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -92,6 +93,7 @@
9293
02CCF4AB193D16930069AEE9 /* Main.storyboard */,
9394
02CCF4AE193D16930069AEE9 /* Images.xcassets */,
9495
02CCF4A5193D16930069AEE9 /* Supporting Files */,
96+
028D579A1944A6C300268B8F /* TestSwift-Bridging-Header.h */,
9597
);
9698
path = TestSwift;
9799
sourceTree = "<group>";
@@ -343,10 +345,13 @@
343345
buildSettings = {
344346
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
345347
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
348+
CLANG_ENABLE_MODULES = YES;
346349
INFOPLIST_FILE = TestSwift/Info.plist;
347350
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
348351
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
349352
PRODUCT_NAME = "$(TARGET_NAME)";
353+
SWIFT_OBJC_BRIDGING_HEADER = "TestSwift/TestSwift-Bridging-Header.h";
354+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
350355
};
351356
name = Debug;
352357
};
@@ -355,10 +360,12 @@
355360
buildSettings = {
356361
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
357362
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
363+
CLANG_ENABLE_MODULES = YES;
358364
INFOPLIST_FILE = TestSwift/Info.plist;
359365
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
360366
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
361367
PRODUCT_NAME = "$(TARGET_NAME)";
368+
SWIFT_OBJC_BRIDGING_HEADER = "TestSwift/TestSwift-Bridging-Header.h";
362369
};
363370
name = Release;
364371
};

TestSwift/APIController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ class APIController {
2828
// Now escape anything else that isn't URL-friendly
2929
let escapedSearchTerm = itunesSearchTerm.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
3030
let urlPath = "https://itunes.apple.com/search?term=\(escapedSearchTerm)&media=music&entity=album"
31-
let url: NSURL = NSURL(string: urlPath)
32-
let request: NSURLRequest = NSURLRequest(URL: url)
31+
let url = NSURL(string: urlPath)
32+
let request = NSURLRequest(URL: url)
3333

3434
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
3535
if error? {
3636
println("ERROR: \(error.localizedDescription)")
3737
}
3838
else {
3939
var error: NSError?
40-
let jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
40+
let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
4141
// Now send the JSON result to our delegate object
4242
if error? {
4343
println("HTTP Error: \(error?.localizedDescription)")

TestSwift/Base.lproj/Main.storyboard

Lines changed: 0 additions & 1 deletion
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>

TestSwift/SearchResultsViewController.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010

1111
class SearchResultsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, APIControllerProtocol {
1212

13-
let kCellIdentifier: String = "SearchResultCell"
13+
let kCellIdentifier = "SearchResultCell"
1414

1515
var api: APIController?
1616

@@ -43,7 +43,7 @@ class SearchResultsViewController: UIViewController, UITableViewDataSource, UITa
4343

4444
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
4545

46-
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as UITableViewCell
46+
var cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as UITableViewCell
4747

4848
// Find this cell's album by passing in the indexPath.row to the subscript method for an array of type Album[]
4949
let album = self.albums[indexPath.row]
@@ -63,11 +63,11 @@ class SearchResultsViewController: UIViewController, UITableViewDataSource, UITa
6363

6464
if( !image? ) {
6565
// If the image does not exist, we need to download it
66-
let imgURL: NSURL = NSURL(string: urlString)
66+
let imgURL = NSURL(string: urlString)
6767

6868
// Download an NSData representation of the image at the URL
69-
let request: NSURLRequest = NSURLRequest(URL: imgURL)
70-
let urlConnection: NSURLConnection = NSURLConnection(request: request, delegate: self)
69+
let request = NSURLRequest(URL: imgURL)
70+
let urlConnection = NSURLConnection(request: request, delegate: self)
7171
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
7272
if !error? {
7373
image = UIImage(data: data)
@@ -106,15 +106,15 @@ class SearchResultsViewController: UIViewController, UITableViewDataSource, UITa
106106
let allResults: NSDictionary[] = results["results"] as NSDictionary[]
107107

108108
// Sometimes iTunes returns a collection, not a track, so we check both for the 'name'
109-
for result: NSDictionary in allResults {
109+
for result in allResults {
110110

111-
var name: String? = result["trackName"] as? String
111+
var name = result["trackName"] as? String
112112
if !name? {
113113
name = result["collectionName"] as? String
114114
}
115115

116116
// Sometimes price comes in as formattedPrice, sometimes as collectionPrice.. and sometimes it's a float instead of a string. Hooray!
117-
var price: String? = result["formattedPrice"] as? String
117+
var price = result["formattedPrice"] as? String
118118
if !price? {
119119
price = result["collectionPrice"] as? String
120120
if !price? {
@@ -127,11 +127,11 @@ class SearchResultsViewController: UIViewController, UITableViewDataSource, UITa
127127
}
128128
}
129129

130-
let thumbnailURL: String? = result["artworkUrl60"] as? String
131-
let imageURL: String? = result["artworkUrl100"] as? String
132-
let artistURL: String? = result["artistViewUrl"] as? String
130+
let thumbnailURL = result["artworkUrl60"] as? String
131+
let imageURL = result["artworkUrl100"] as? String
132+
let artistURL = result["artistViewUrl"] as? String
133133

134-
var itemURL: String? = result["collectionViewUrl"] as? String
134+
var itemURL = result["collectionViewUrl"] as? String
135135
if !itemURL? {
136136
itemURL = result["trackViewUrl"] as? String
137137
}

TestSwift/TestSwift-Bridging-Header.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+
5+
#import <MediaPlayer/MediaPlayer.h>

0 commit comments

Comments
 (0)