Skip to content

Commit fbd206f

Browse files
authored
Merge pull request #59 from muyexi/swift3
convert to swift 3
2 parents 6c2d09c + a03a203 commit fbd206f

17 files changed

+109
-87
lines changed

Podfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
PODS:
2-
- Nimble (4.0.1)
3-
- Quick (0.9.2)
4-
- SwiftyJSON (2.3.2)
2+
- Nimble (6.0.1)
3+
- Quick (1.1.0)
4+
- SwiftyJSON (3.1.4)
55

66
DEPENDENCIES:
77
- Nimble
88
- Quick
99
- SwiftyJSON
1010

1111
SPEC CHECKSUMS:
12-
Nimble: 0f3c8b8b084cda391209c3c5efbb48bedeeb920a
13-
Quick: 18d057bc66451eedd5d1c8dc99ba2a5db6e60226
14-
SwiftyJSON: 04ccea08915aa0109039157c7974cf0298da292a
12+
Nimble: 1527fd1bd2b4cf0636251a36bc8ab37e81da8347
13+
Quick: dafc587e21eed9f4cab3249b9f9015b0b7a7f71d
14+
SwiftyJSON: c2842d878f95482ffceec5709abc3d05680c0220
1515

1616
PODFILE CHECKSUM: 2ec46d3741ab466dee64c9e763366836879c1f6e
1717

18-
COCOAPODS: 1.0.1
18+
COCOAPODS: 1.2.0

SwiftWeather.xcodeproj/project.pbxproj

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,21 @@
365365
isa = PBXProject;
366366
attributes = {
367367
LastSwiftUpdateCheck = 0710;
368-
LastUpgradeCheck = 0700;
368+
LastUpgradeCheck = 0820;
369369
ORGANIZATIONNAME = "Jake Lin";
370370
TargetAttributes = {
371371
AECBA5E11B836BF20004A536 = {
372372
CreatedOnToolsVersion = 7.0;
373+
LastSwiftMigration = 0820;
373374
};
374375
AECBA5F51B836BF20004A536 = {
375376
CreatedOnToolsVersion = 7.0;
377+
LastSwiftMigration = 0820;
376378
TestTargetID = AECBA5E11B836BF20004A536;
377379
};
378380
AECBA6001B836BF20004A536 = {
379381
CreatedOnToolsVersion = 7.0;
382+
LastSwiftMigration = 0820;
380383
TestTargetID = AECBA5E11B836BF20004A536;
381384
};
382385
};
@@ -443,7 +446,7 @@
443446
);
444447
runOnlyForDeploymentPostprocessing = 0;
445448
shellPath = /bin/sh;
446-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
449+
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
447450
showEnvVarsInLog = 0;
448451
};
449452
3211EE071253F1D6513A17BA /* [CP] Embed Pods Frameworks */ = {
@@ -503,7 +506,7 @@
503506
);
504507
runOnlyForDeploymentPostprocessing = 0;
505508
shellPath = /bin/sh;
506-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
509+
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
507510
showEnvVarsInLog = 0;
508511
};
509512
ADD0EBFC1C562E52002D8392 /* ShellScript */ = {
@@ -630,8 +633,10 @@
630633
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
631634
CLANG_WARN_EMPTY_BODY = YES;
632635
CLANG_WARN_ENUM_CONVERSION = YES;
636+
CLANG_WARN_INFINITE_RECURSION = YES;
633637
CLANG_WARN_INT_CONVERSION = YES;
634638
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
639+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
635640
CLANG_WARN_UNREACHABLE_CODE = YES;
636641
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
637642
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -658,6 +663,7 @@
658663
ONLY_ACTIVE_ARCH = YES;
659664
SDKROOT = iphoneos;
660665
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
666+
SWIFT_VERSION = 3.0;
661667
TARGETED_DEVICE_FAMILY = "1,2";
662668
};
663669
name = Debug;
@@ -675,8 +681,10 @@
675681
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
676682
CLANG_WARN_EMPTY_BODY = YES;
677683
CLANG_WARN_ENUM_CONVERSION = YES;
684+
CLANG_WARN_INFINITE_RECURSION = YES;
678685
CLANG_WARN_INT_CONVERSION = YES;
679686
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
687+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
680688
CLANG_WARN_UNREACHABLE_CODE = YES;
681689
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
682690
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -695,6 +703,8 @@
695703
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
696704
MTL_ENABLE_DEBUG_INFO = NO;
697705
SDKROOT = iphoneos;
706+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
707+
SWIFT_VERSION = 3.0;
698708
TARGETED_DEVICE_FAMILY = "1,2";
699709
VALIDATE_PRODUCT = YES;
700710
};
@@ -705,10 +715,12 @@
705715
baseConfigurationReference = 900AFFBB41C69FC277CB0A33 /* Pods-SwiftWeather.debug.xcconfig */;
706716
buildSettings = {
707717
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
718+
DEVELOPMENT_TEAM = "";
708719
INFOPLIST_FILE = SwiftWeather/Info.plist;
709720
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
710721
PRODUCT_BUNDLE_IDENTIFIER = com.rushjet.SwiftWeather;
711722
PRODUCT_NAME = "$(TARGET_NAME)";
723+
SWIFT_VERSION = 3.0;
712724
};
713725
name = Debug;
714726
};
@@ -717,10 +729,12 @@
717729
baseConfigurationReference = E835C39D4B929F35B6A57B12 /* Pods-SwiftWeather.release.xcconfig */;
718730
buildSettings = {
719731
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
732+
DEVELOPMENT_TEAM = "";
720733
INFOPLIST_FILE = SwiftWeather/Info.plist;
721734
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
722735
PRODUCT_BUNDLE_IDENTIFIER = com.rushjet.SwiftWeather;
723736
PRODUCT_NAME = "$(TARGET_NAME)";
737+
SWIFT_VERSION = 3.0;
724738
};
725739
name = Release;
726740
};
@@ -730,11 +744,13 @@
730744
buildSettings = {
731745
BUNDLE_LOADER = "$(TEST_HOST)";
732746
CLANG_ENABLE_MODULES = YES;
747+
DEVELOPMENT_TEAM = "";
733748
INFOPLIST_FILE = SwiftWeatherTests/Info.plist;
734749
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
735750
PRODUCT_BUNDLE_IDENTIFIER = com.rushjet.SwiftWeatherTests;
736751
PRODUCT_NAME = "$(TARGET_NAME)";
737752
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
753+
SWIFT_VERSION = 3.0;
738754
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftWeather.app/SwiftWeather";
739755
};
740756
name = Debug;
@@ -745,21 +761,25 @@
745761
buildSettings = {
746762
BUNDLE_LOADER = "$(TEST_HOST)";
747763
CLANG_ENABLE_MODULES = YES;
764+
DEVELOPMENT_TEAM = "";
748765
INFOPLIST_FILE = SwiftWeatherTests/Info.plist;
749766
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
750767
PRODUCT_BUNDLE_IDENTIFIER = com.rushjet.SwiftWeatherTests;
751768
PRODUCT_NAME = "$(TARGET_NAME)";
769+
SWIFT_VERSION = 3.0;
752770
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftWeather.app/SwiftWeather";
753771
};
754772
name = Release;
755773
};
756774
AECBA6111B836BF20004A536 /* Debug */ = {
757775
isa = XCBuildConfiguration;
758776
buildSettings = {
777+
DEVELOPMENT_TEAM = "";
759778
INFOPLIST_FILE = SwiftWeatherUITests/Info.plist;
760779
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
761780
PRODUCT_BUNDLE_IDENTIFIER = com.rushjet.SwiftWeatherUITests;
762781
PRODUCT_NAME = "$(TARGET_NAME)";
782+
SWIFT_VERSION = 3.0;
763783
TEST_TARGET_NAME = SwiftWeather;
764784
USES_XCTRUNNER = YES;
765785
};
@@ -768,10 +788,12 @@
768788
AECBA6121B836BF20004A536 /* Release */ = {
769789
isa = XCBuildConfiguration;
770790
buildSettings = {
791+
DEVELOPMENT_TEAM = "";
771792
INFOPLIST_FILE = SwiftWeatherUITests/Info.plist;
772793
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
773794
PRODUCT_BUNDLE_IDENTIFIER = com.rushjet.SwiftWeatherUITests;
774795
PRODUCT_NAME = "$(TARGET_NAME)";
796+
SWIFT_VERSION = 3.0;
775797
TEST_TARGET_NAME = SwiftWeather;
776798
USES_XCTRUNNER = YES;
777799
};

SwiftWeather/AppDelegate.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication,
18-
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication,
18+
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1919
// Override point for customization after application launch.
2020
return true
2121
}
2222

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

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

39-
func applicationWillEnterForeground(application: UIApplication) {
39+
func applicationWillEnterForeground(_ application: UIApplication) {
4040
// Called as part of the transition from the background to the inactive state; here you can undo
4141
// 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.
4646
// If the application was previously in the background, optionally refresh the user interface.
4747
}
4848

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

SwiftWeather/Error.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
import Foundation
77

8-
struct Error {
8+
struct SWError {
99
enum Code: Int {
10-
case URLError = -6000
11-
case NetworkRequestFailed = -6001
12-
case JSONSerializationFailed = -6002
13-
case JSONParsingFailed = -6003
10+
case urlError = -6000
11+
case networkRequestFailed = -6001
12+
case jsonSerializationFailed = -6002
13+
case jsonParsingFailed = -6003
1414
}
1515

1616
let errorCode: Code

SwiftWeather/ForecastDateTime.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ struct ForecastDateTime {
1313
}
1414

1515
var shortTime: String {
16-
let dateFormatter = NSDateFormatter()
16+
let dateFormatter = DateFormatter()
1717
dateFormatter.dateFormat = "HH:mm"
18-
let date = NSDate(timeIntervalSince1970: rawDate)
19-
return dateFormatter.stringFromDate(date)
18+
let date = Date(timeIntervalSince1970: rawDate)
19+
return dateFormatter.string(from: date)
2020
}
2121
}

SwiftWeather/ForecastView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import UIKit
2525
}
2626

2727
func loadViewFromNib() -> UIView {
28-
let bundle = NSBundle(forClass: self.dynamicType)
28+
let bundle = Bundle(for: type(of: self))
2929
let nib = UINib(nibName: nibName(), bundle: bundle)
3030
// swiftlint:disable force_cast
31-
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
31+
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
3232
// swiftlint:enable force_cast
3333

3434
view.frame = bounds
35-
view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
35+
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
3636
addSubview(view)
3737
return view
3838
}
@@ -57,7 +57,7 @@ import UIKit
5757
}
5858
}
5959

60-
func loadViewModel(viewModel: ForecastViewModel) {
60+
func loadViewModel(_ viewModel: ForecastViewModel) {
6161
self.viewModel = viewModel
6262
}
6363

@@ -133,7 +133,7 @@ import UIKit
133133
}
134134

135135
// MARK: - Private
136-
private func nibName() -> String {
137-
return String(self.dynamicType)
136+
fileprivate func nibName() -> String {
137+
return String(describing: type(of: self))
138138
}
139139
}

SwiftWeather/LocationService.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import Foundation
77
import CoreLocation
88

99
protocol LocationServiceDelegate {
10-
func locationDidUpdate(service: LocationService, location: CLLocation)
10+
func locationDidUpdate(_ service: LocationService, location: CLLocation)
1111
}
1212

1313
class LocationService: NSObject {
1414
var delegate: LocationServiceDelegate?
1515

16-
private let locationManager = CLLocationManager()
16+
fileprivate let locationManager = CLLocationManager()
1717

1818
override init() {
1919
super.init()
@@ -30,14 +30,14 @@ class LocationService: NSObject {
3030

3131
// MARK: - CLLocationManagerDelegate
3232
extension LocationService : CLLocationManagerDelegate {
33-
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
33+
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
3434
if let location = locations.first {
3535
print("Current location: \(location)")
3636
delegate?.locationDidUpdate(self, location: location)
3737
}
3838
}
3939

40-
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
40+
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
4141
print("Error finding location: \(error.localizedDescription)")
4242
}
4343
}

SwiftWeather/Observable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import Foundation
77

88
class Observable<T> {
9-
typealias Observer = T -> Void
9+
typealias Observer = (T) -> Void
1010
var observer: Observer?
1111

12-
func observe(observer: Observer?) {
12+
func observe(_ observer: Observer?) {
1313
self.observer = observer
1414
observer?(value)
1515
}

0 commit comments

Comments
 (0)