Skip to content

Commit 201d023

Browse files
committed
Upgrade to Swift 3
1 parent a2a36a1 commit 201d023

12 files changed

+3018
-1723
lines changed

src/TechStacks.xcodeproj/project.pbxproj

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

99
/* Begin PBXBuildFile section */
10-
25CAD1011BB8BEE5007800C2 /* TechStacks.dtos.extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25CAD1001BB8BEE5007800C2 /* TechStacks.dtos.extras.swift */; settings = {ASSET_TAGS = (); }; };
1110
5162D4321A8234D7005AC7E2 /* TechnologiesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5162D4311A8234D7005AC7E2 /* TechnologiesViewController.swift */; };
1211
5162D4341A82B82D005AC7E2 /* TechnologyDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5162D4331A82B82D005AC7E2 /* TechnologyDetailViewController.swift */; };
1312
51A0817D1A7F6DB5000590E9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A0817C1A7F6DB5000590E9 /* AppDelegate.swift */; };
@@ -38,7 +37,6 @@
3837
/* End PBXCopyFilesBuildPhase section */
3938

4039
/* Begin PBXFileReference section */
41-
25CAD1001BB8BEE5007800C2 /* TechStacks.dtos.extras.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TechStacks.dtos.extras.swift; sourceTree = "<group>"; };
4240
5162D4311A8234D7005AC7E2 /* TechnologiesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TechnologiesViewController.swift; sourceTree = "<group>"; };
4341
5162D4331A82B82D005AC7E2 /* TechnologyDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TechnologyDetailViewController.swift; sourceTree = "<group>"; };
4442
51A081771A7F6DB5000590E9 /* TechStacks.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TechStacks.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -101,7 +99,6 @@
10199
51A081871A7F6DB6000590E9 /* LaunchScreen.xib */,
102100
51A081FB1A80455B000590E9 /* JsonServiceClient.swift */,
103101
51A081F41A7F73FC000590E9 /* TechStacks.dtos.swift */,
104-
25CAD1001BB8BEE5007800C2 /* TechStacks.dtos.extras.swift */,
105102
51D0210A1A87875C007D973F /* Image.xcassets */,
106103
);
107104
path = TechStacks;
@@ -149,6 +146,7 @@
149146
51A081761A7F6DB5000590E9 = {
150147
CreatedOnToolsVersion = 6.1.1;
151148
DevelopmentTeam = DK4VJ3YB24;
149+
LastSwiftMigration = 0810;
152150
};
153151
};
154152
};
@@ -193,7 +191,6 @@
193191
51F0B9BB1A809803003910E7 /* UIExtensions.swift in Sources */,
194192
51F0B9B91A8090E8003910E7 /* HeaderViewController.swift in Sources */,
195193
51F0B9BD1A80A0D1003910E7 /* AppData.swift in Sources */,
196-
25CAD1011BB8BEE5007800C2 /* TechStacks.dtos.extras.swift in Sources */,
197194
51A0817D1A7F6DB5000590E9 /* AppDelegate.swift in Sources */,
198195
5162D4341A82B82D005AC7E2 /* TechnologyDetailViewController.swift in Sources */,
199196
51A0817F1A7F6DB5000590E9 /* HomeViewController.swift in Sources */,
@@ -319,6 +316,7 @@
319316
PRODUCT_BUNDLE_IDENTIFIER = "net.servicestack.$(PRODUCT_NAME:rfc1034identifier)";
320317
PRODUCT_NAME = "$(TARGET_NAME)";
321318
PROVISIONING_PROFILE = "c4b6145b-435c-41db-9a98-708a6d46f25d";
319+
SWIFT_VERSION = 3.0;
322320
};
323321
name = Debug;
324322
};
@@ -331,6 +329,7 @@
331329
PRODUCT_BUNDLE_IDENTIFIER = "net.servicestack.$(PRODUCT_NAME:rfc1034identifier)";
332330
PRODUCT_NAME = "$(TARGET_NAME)";
333331
PROVISIONING_PROFILE = "c4b6145b-435c-41db-9a98-708a6d46f25d";
332+
SWIFT_VERSION = 3.0;
334333
};
335334
name = Release;
336335
};

src/TechStacks/AppData.swift

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

1212

13-
public class AppData : NSObject
13+
open class AppData : NSObject
1414
{
1515
var client = JsonServiceClient(baseUrl: "http://techstacks.io")
1616

@@ -21,20 +21,20 @@ public class AppData : NSObject
2121
static let AllTechnologyStacks = "allTechnologyStacks"
2222
}
2323

24-
public dynamic var allTiers:[Option] = []
24+
open dynamic var allTiers:[Option] = []
2525

26-
public dynamic var overview:AppOverviewResponse = AppOverviewResponse()
27-
public dynamic var topTechnologies:[TechnologyInfo] = []
26+
open dynamic var overview:AppOverviewResponse = AppOverviewResponse()
27+
open dynamic var topTechnologies:[TechnologyInfo] = []
2828

29-
public dynamic var allTechnologies:[Technology] = []
30-
public dynamic var allTechnologyStacks:[TechnologyStack] = []
29+
open dynamic var allTechnologies:[Technology] = []
30+
open dynamic var allTechnologyStacks:[TechnologyStack] = []
3131

32-
public dynamic var search:String?
33-
public dynamic var filteredTechStacks:[TechnologyStack] = []
34-
public dynamic var filteredTechnologies:[Technology] = []
32+
open dynamic var search:String?
33+
open dynamic var filteredTechStacks:[TechnologyStack] = []
34+
open dynamic var filteredTechnologies:[Technology] = []
3535

36-
public var technologyStackCache:[String:GetTechnologyStackResponse] = [:]
37-
public var technologyCache:[String:GetTechnologyResponse] = [:]
36+
open var technologyStackCache:[String:GetTechnologyStackResponse] = [:]
37+
open var technologyCache:[String:GetTechnologyResponse] = [:]
3838

3939
override init(){
4040
super.init()
@@ -67,7 +67,7 @@ public class AppData : NSObject
6767
}
6868
}
6969

70-
func loadTechnologyStack(slug:String) -> Promise<GetTechnologyStackResponse> {
70+
func loadTechnologyStack(_ slug:String) -> Promise<GetTechnologyStackResponse> {
7171
if let response = technologyStackCache[slug] {
7272
return Promise<GetTechnologyStackResponse> { (complete,reject) in complete(response) }
7373
}
@@ -81,17 +81,17 @@ public class AppData : NSObject
8181
}
8282
}
8383

84-
func searchTechStacks(query:String) -> Promise<FindTechStacksResponse> {
84+
func searchTechStacks(_ query:String) -> Promise<QueryResponse<TechnologyStack>> {
8585
self.search = query
8686

87-
return client.getAsync(FindTechStacks(), query: ["NameContains":query, "DescriptionContains":query])
88-
.then { r -> FindTechStacksResponse in
87+
return client.getAsync(FindTechStacks<TechnologyStack>(), query: ["NameContains":query, "DescriptionContains":query])
88+
.then { r -> QueryResponse<TechnologyStack> in
8989
self.filteredTechStacks = r.results
9090
return r
9191
}
9292
}
9393

94-
func loadTechnology(slug:String) -> Promise<GetTechnologyResponse> {
94+
func loadTechnology(_ slug:String) -> Promise<GetTechnologyResponse> {
9595
if let response = technologyCache[slug] {
9696
return Promise<GetTechnologyResponse> { (complete,reject) in complete(response) }
9797
}
@@ -105,11 +105,11 @@ public class AppData : NSObject
105105
}
106106
}
107107

108-
func searchTechnologies(query:String) -> Promise<FindTechnologiesResponse> {
108+
func searchTechnologies(_ query:String) -> Promise<QueryResponse<Technology>> {
109109
self.search = query
110110

111-
return client.getAsync(FindTechnologies(), query:["NameContains":query, "DescriptionContains":query])
112-
.then { r -> FindTechnologiesResponse in
111+
return client.getAsync(FindTechnologies<Technology>(), query:["NameContains":query, "DescriptionContains":query])
112+
.then { r -> QueryResponse<Technology> in
113113
self.filteredTechnologies = r.results
114114
return r
115115
}
@@ -119,12 +119,12 @@ public class AppData : NSObject
119119
func loadDefaultImageCaches() {
120120
imageCache["stacks"] = UIImage(named: "stacks")
121121

122-
UIGraphicsBeginImageContextWithOptions(CGSizeMake(858, 689), false, 0.0)
122+
UIGraphicsBeginImageContextWithOptions(CGSize(width: 858, height: 689), false, 0.0)
123123
imageCache["blankScreenshot"] = UIGraphicsGetImageFromCurrentImageContext()
124124
UIGraphicsEndImageContext()
125125
}
126126

127-
public func loadAllImagesAsync(urls:[String]) -> Promise<[String:UIImage?]> {
127+
open func loadAllImagesAsync(_ urls:[String]) -> Promise<[String:UIImage?]> {
128128
var images = [String:UIImage?]()
129129
return Promise<[String:UIImage?]> { (complete, reject) in
130130
for url in urls {
@@ -139,13 +139,13 @@ public class AppData : NSObject
139139
}
140140
}
141141

142-
public func loadImageAsync(url:String) -> Promise<UIImage?> {
142+
open func loadImageAsync(_ url:String) -> Promise<UIImage?> {
143143
if let image = imageCache[url] {
144144
return Promise<UIImage?> { (complete, reject) in complete(image) }
145145
}
146146

147147
return client.getDataAsync(url)
148-
.then { (data:NSData) -> UIImage? in
148+
.then { (data:Data) -> UIImage? in
149149
if let image = UIImage(data:data) {
150150
self.imageCache[url] = image
151151
return image
@@ -156,23 +156,23 @@ public class AppData : NSObject
156156

157157
/* KVO Observable helpers */
158158
var observedProperties = [NSObject:[String]]()
159-
var ctx:AnyObject = 1
159+
var ctx:AnyObject = 1 as AnyObject
160160

161-
public func observe(observer: NSObject, properties:[String]) {
161+
open func observe(_ observer: NSObject, properties:[String]) {
162162
for property in properties {
163163
self.observe(observer, property: property)
164164
}
165165
}
166166

167-
public func observe(observer: NSObject, property:String) {
168-
self.addObserver(observer, forKeyPath: property, options: [.New , .Old], context: &ctx)
167+
open func observe(_ observer: NSObject, property:String) {
168+
self.addObserver(observer, forKeyPath: property, options: [.new , .old], context: &ctx)
169169

170170
var properties = observedProperties[observer] ?? [String]()
171171
properties.append(property)
172172
observedProperties[observer] = properties
173173
}
174174

175-
public func unobserve(observer: NSObject) {
175+
open func unobserve(_ observer: NSObject) {
176176
if let properties = observedProperties[observer] {
177177
for property in properties {
178178
self.removeObserver(observer, forKeyPath: property, context: &ctx)

src/TechStacks/AppDelegate.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,43 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1717
// Override point for customization after application launch.
1818

1919
//https://coderwall.com/p/dyqrfa/customize-navigation-bar-appearance-with-swift
2020
let navigationBarAppearace = UINavigationBar.appearance()
21-
navigationBarAppearace.translucent = false
22-
navigationBarAppearace.tintColor = UIColor.whiteColor()
21+
navigationBarAppearace.isTranslucent = false
22+
navigationBarAppearace.tintColor = UIColor.white
2323
navigationBarAppearace.barTintColor = UIColor(red: 0.0, green: 0.58431372550000005, blue: 0.96078431369999995, alpha: 1.0)
24-
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
25-
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
24+
navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]
25+
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
2626

2727
return true
2828
}
2929

30-
func applicationWillResignActive(application: UIApplication) {
30+
func applicationWillResignActive(_ application: UIApplication) {
3131
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
3232
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
3333
}
3434

35-
func applicationDidEnterBackground(application: UIApplication) {
35+
func applicationDidEnterBackground(_ application: UIApplication) {
3636
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
3737
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3838
}
3939

40-
func applicationWillEnterForeground(application: UIApplication) {
40+
func applicationWillEnterForeground(_ application: UIApplication) {
4141
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
4242
}
4343

44-
func applicationDidBecomeActive(application: UIApplication) {
44+
func applicationDidBecomeActive(_ application: UIApplication) {
4545
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
4646
}
4747

48-
func applicationWillTerminate(application: UIApplication) {
48+
func applicationWillTerminate(_ application: UIApplication) {
4949
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
5050
}
5151

52-
func applicationDidReceiveMemoryWarning(application: UIApplication) {
52+
func applicationDidReceiveMemoryWarning(_ application: UIApplication) {
5353
appData.resetCache()
5454
}
5555

src/TechStacks/HomeViewController.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HomeViewController: UIViewController, UITableViewDelegate, UITableViewData
1616
@IBOutlet weak var technologyPicker: UIPickerView!
1717
var selectedTechnology:TechnologyTier?
1818

19-
override func viewWillAppear(animated: Bool) {
19+
override func viewWillAppear(_ animated: Bool) {
2020
}
2121

2222
override func viewDidLoad() {
@@ -32,7 +32,7 @@ class HomeViewController: UIViewController, UITableViewDelegate, UITableViewData
3232
self.appData.loadOverview()
3333
}
3434

35-
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
35+
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
3636
if let kp = keyPath {
3737
switch kp {
3838
case AppData.Property.AllTiers:
@@ -52,50 +52,50 @@ class HomeViewController: UIViewController, UITableViewDelegate, UITableViewData
5252
}
5353

5454
/* PickerView */
55-
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
55+
func numberOfComponents(in pickerView: UIPickerView) -> Int {
5656
return 1
5757
}
5858

59-
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
59+
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
6060
return appData.allTiers.count
6161
}
6262

63-
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
63+
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
6464
return appData.allTiers[row].title
6565
}
6666

67-
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
67+
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
6868
self.selectedTechnology = appData.allTiers[row].value
6969
tblView.reloadData()
7070
}
7171

7272
/* TableView */
73-
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
73+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
7474
return selectedTechnologies.count
7575
}
7676

77-
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
77+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
7878

7979
var cell: UITableViewCell
80-
if let viewCell = self.tblView.dequeueReusableCellWithIdentifier("cellHome") as UITableViewCell? {
80+
if let viewCell = self.tblView.dequeueReusableCell(withIdentifier: "cellHome") as UITableViewCell? {
8181
cell = viewCell
8282
} else {
8383
cell = UITableViewCell()
8484
}
8585

86-
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
86+
cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
8787
let tech = selectedTechnologies[indexPath.row]
8888
cell.textLabel?.text = "\(tech.name!) (\(tech.stacksCount!))"
89-
cell.textLabel!.font = cell.textLabel!.font.fontWithSize(Style.tableCellTitleSize)
89+
cell.textLabel!.font = cell.textLabel!.font.withSize(Style.tableCellTitleSize)
9090

9191
return cell
9292
}
9393

94-
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
94+
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
9595
return Style.tableCellHeight
9696
}
9797

98-
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
98+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
9999
let selected = selectedTechnologies[indexPath.row]
100100
self.navigationController?.openTechnology(selected.slug!)
101101
}

0 commit comments

Comments
 (0)