Skip to content

Commit 6a4645b

Browse files
authored
Merge pull request #57 from mapbox/swift3
Migrate to Swift 3
2 parents 3986975 + 1e04971 commit 6a4645b

15 files changed

+361
-353
lines changed

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0

Geocoder Example/AppDelegate.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import UIKit
22

33
@UIApplicationMain
4-
54
class AppDelegate: UIResponder, UIApplicationDelegate {
6-
75
var window: UIWindow?
86

9-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
10-
window = UIWindow(frame: UIScreen.mainScreen().bounds)
7+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
8+
window = UIWindow(frame: UIScreen.main.bounds)
119
window!.rootViewController = ViewController(nibName: nil, bundle: nil)
1210
window!.makeKeyAndVisible()
1311

1412
return true
1513
}
16-
1714
}

Geocoder Example/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ - (void)mapView:(MGLMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
5656
[self.geocodingDataTask cancel];
5757
MBReverseGeocodeOptions *options = [[MBReverseGeocodeOptions alloc] initWithCoordinate:self.mapView.centerCoordinate];
5858
options.allowedScopes = MBPlacemarkScopeAll;
59-
[self.geocoder geocodeWithOptions:options completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) {
59+
[self.geocoder geocode:options completionHandler:^(NSArray<MBGeocodedPlacemark *> * _Nullable placemarks, NSString * _Nullable attribution, NSError * _Nullable error) {
6060
if (error) {
6161
NSLog(@"%@", error);
6262
} else if (placemarks.count > 0) {

Geocoder Example/ViewController.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ViewController: UIViewController, MGLMapViewDelegate {
1414
var mapView: MGLMapView!
1515
var resultsLabel: UILabel!
1616
var geocoder: Geocoder!
17-
var geocodingDataTask: NSURLSessionDataTask?
17+
var geocodingDataTask: URLSessionDataTask?
1818

1919
// MARK: - Setup
2020

@@ -25,33 +25,33 @@ class ViewController: UIViewController, MGLMapViewDelegate {
2525

2626
MGLAccountManager.setAccessToken(MapboxAccessToken)
2727
mapView = MGLMapView(frame: view.bounds)
28-
mapView.autoresizingMask = [ .FlexibleWidth, .FlexibleHeight ]
28+
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
2929
mapView.delegate = self
3030
view.addSubview(mapView)
3131

3232
resultsLabel = UILabel(frame: CGRect(x: 10, y: 20, width: view.bounds.size.width - 20, height: 30))
33-
resultsLabel.autoresizingMask = .FlexibleWidth
33+
resultsLabel.autoresizingMask = .flexibleWidth
3434
resultsLabel.adjustsFontSizeToFitWidth = true
35-
resultsLabel.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)
36-
resultsLabel.userInteractionEnabled = false
35+
resultsLabel.backgroundColor = UIColor.white.withAlphaComponent(0.5)
36+
resultsLabel.isUserInteractionEnabled = false
3737
view.addSubview(resultsLabel)
3838

3939
geocoder = Geocoder(accessToken: MapboxAccessToken)
4040
}
4141

4242
// MARK: - MGLMapViewDelegate
4343

44-
func mapView(mapView: MGLMapView, regionWillChangeAnimated animated: Bool) {
44+
func mapView(_ mapView: MGLMapView, regionWillChangeAnimated animated: Bool) {
4545
geocodingDataTask?.cancel()
4646
}
4747

48-
func mapView(mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
48+
func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
4949
geocodingDataTask?.cancel()
5050
let options = ReverseGeocodeOptions(coordinate: mapView.centerCoordinate)
51-
geocodingDataTask = geocoder.geocode(options: options) { [unowned self] (placemarks, attribution, error) in
51+
geocodingDataTask = geocoder.geocode(options) { [unowned self] (placemarks, attribution, error) in
5252
if let error = error {
5353
NSLog("%@", error)
54-
} else if let placemarks = placemarks where !placemarks.isEmpty {
54+
} else if let placemarks = placemarks, !placemarks.isEmpty {
5555
self.resultsLabel.text = placemarks[0].qualifiedName
5656
} else {
5757
self.resultsLabel.text = "No results"

MapboxGeocoder.xcodeproj/project.pbxproj

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@
11881188
PRODUCT_NAME = MapboxGeocoder;
11891189
SDKROOT = macosx;
11901190
SKIP_INSTALL = YES;
1191-
SWIFT_VERSION = 2.3;
1191+
SWIFT_VERSION = 3.0;
11921192
VERSIONING_SYSTEM = "apple-generic";
11931193
VERSION_INFO_PREFIX = "";
11941194
};
@@ -1216,7 +1216,8 @@
12161216
PRODUCT_NAME = MapboxGeocoder;
12171217
SDKROOT = macosx;
12181218
SKIP_INSTALL = YES;
1219-
SWIFT_VERSION = 2.3;
1219+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1220+
SWIFT_VERSION = 3.0;
12201221
VERSIONING_SYSTEM = "apple-generic";
12211222
VERSION_INFO_PREFIX = "";
12221223
};
@@ -1236,7 +1237,7 @@
12361237
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGeocoderTests;
12371238
PRODUCT_NAME = MapboxGeocoderTests;
12381239
SDKROOT = macosx;
1239-
SWIFT_VERSION = 2.3;
1240+
SWIFT_VERSION = 3.0;
12401241
};
12411242
name = Debug;
12421243
};
@@ -1255,7 +1256,8 @@
12551256
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGeocoderTests;
12561257
PRODUCT_NAME = MapboxGeocoderTests;
12571258
SDKROOT = macosx;
1258-
SWIFT_VERSION = 2.3;
1259+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1260+
SWIFT_VERSION = 3.0;
12591261
};
12601262
name = Release;
12611263
};
@@ -1278,7 +1280,7 @@
12781280
PRODUCT_NAME = MapboxGeocoder;
12791281
SDKROOT = appletvos;
12801282
SKIP_INSTALL = YES;
1281-
SWIFT_VERSION = 2.3;
1283+
SWIFT_VERSION = 3.0;
12821284
TARGETED_DEVICE_FAMILY = 3;
12831285
TVOS_DEPLOYMENT_TARGET = 9.0;
12841286
VERSIONING_SYSTEM = "apple-generic";
@@ -1306,7 +1308,8 @@
13061308
PRODUCT_NAME = MapboxGeocoder;
13071309
SDKROOT = appletvos;
13081310
SKIP_INSTALL = YES;
1309-
SWIFT_VERSION = 2.3;
1311+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1312+
SWIFT_VERSION = 3.0;
13101313
TARGETED_DEVICE_FAMILY = 3;
13111314
TVOS_DEPLOYMENT_TARGET = 9.0;
13121315
VERSIONING_SYSTEM = "apple-generic";
@@ -1326,7 +1329,7 @@
13261329
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGeocoderTests;
13271330
PRODUCT_NAME = MapboxGeocoderTests;
13281331
SDKROOT = appletvos;
1329-
SWIFT_VERSION = 2.3;
1332+
SWIFT_VERSION = 3.0;
13301333
TVOS_DEPLOYMENT_TARGET = 9.0;
13311334
};
13321335
name = Debug;
@@ -1344,7 +1347,8 @@
13441347
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGeocoderTests;
13451348
PRODUCT_NAME = MapboxGeocoderTests;
13461349
SDKROOT = appletvos;
1347-
SWIFT_VERSION = 2.3;
1350+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1351+
SWIFT_VERSION = 3.0;
13481352
TVOS_DEPLOYMENT_TARGET = 9.0;
13491353
};
13501354
name = Release;
@@ -1369,7 +1373,7 @@
13691373
PRODUCT_NAME = MapboxGeocoder;
13701374
SDKROOT = watchos;
13711375
SKIP_INSTALL = YES;
1372-
SWIFT_VERSION = 2.3;
1376+
SWIFT_VERSION = 3.0;
13731377
TARGETED_DEVICE_FAMILY = 4;
13741378
VERSIONING_SYSTEM = "apple-generic";
13751379
VERSION_INFO_PREFIX = "";
@@ -1398,7 +1402,8 @@
13981402
PRODUCT_NAME = MapboxGeocoder;
13991403
SDKROOT = watchos;
14001404
SKIP_INSTALL = YES;
1401-
SWIFT_VERSION = 2.3;
1405+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1406+
SWIFT_VERSION = 3.0;
14021407
TARGETED_DEVICE_FAMILY = 4;
14031408
VERSIONING_SYSTEM = "apple-generic";
14041409
VERSION_INFO_PREFIX = "";
@@ -1451,7 +1456,7 @@
14511456
ONLY_ACTIVE_ARCH = YES;
14521457
SDKROOT = iphoneos;
14531458
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
1454-
SWIFT_VERSION = 2.3;
1459+
SWIFT_VERSION = 3.0;
14551460
TARGETED_DEVICE_FAMILY = "1,2";
14561461
};
14571462
name = Debug;
@@ -1493,7 +1498,7 @@
14931498
MTL_ENABLE_DEBUG_INFO = NO;
14941499
SDKROOT = iphoneos;
14951500
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1496-
SWIFT_VERSION = 2.3;
1501+
SWIFT_VERSION = 3.0;
14971502
TARGETED_DEVICE_FAMILY = "1,2";
14981503
VALIDATE_PRODUCT = YES;
14991504
};
@@ -1509,7 +1514,7 @@
15091514
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
15101515
PRODUCT_BUNDLE_IDENTIFIER = "com.mapbox.$(PRODUCT_NAME:rfc1034identifier)";
15111516
PRODUCT_NAME = "Geocoder (Swift)";
1512-
SWIFT_VERSION = 2.3;
1517+
SWIFT_VERSION = 3.0;
15131518
};
15141519
name = Debug;
15151520
};
@@ -1523,7 +1528,8 @@
15231528
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
15241529
PRODUCT_BUNDLE_IDENTIFIER = "com.mapbox.$(PRODUCT_NAME:rfc1034identifier)";
15251530
PRODUCT_NAME = "Geocoder (Swift)";
1526-
SWIFT_VERSION = 2.3;
1531+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1532+
SWIFT_VERSION = 3.0;
15271533
};
15281534
name = Release;
15291535
};
@@ -1548,7 +1554,7 @@
15481554
PRODUCT_NAME = "$(TARGET_NAME)";
15491555
SKIP_INSTALL = YES;
15501556
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
1551-
SWIFT_VERSION = 2.3;
1557+
SWIFT_VERSION = 3.0;
15521558
VERSIONING_SYSTEM = "apple-generic";
15531559
VERSION_INFO_PREFIX = "";
15541560
};
@@ -1570,7 +1576,8 @@
15701576
PRODUCT_BUNDLE_IDENTIFIER = "com.mapbox.$(PRODUCT_NAME:rfc1034identifier)";
15711577
PRODUCT_NAME = "$(TARGET_NAME)";
15721578
SKIP_INSTALL = YES;
1573-
SWIFT_VERSION = 2.3;
1579+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1580+
SWIFT_VERSION = 3.0;
15741581
VERSIONING_SYSTEM = "apple-generic";
15751582
VERSION_INFO_PREFIX = "";
15761583
};
@@ -1580,7 +1587,6 @@
15801587
isa = XCBuildConfiguration;
15811588
baseConfigurationReference = EE520C91CE4B71A3A3472702 /* Pods-Example (Objective-C).debug.xcconfig */;
15821589
buildSettings = {
1583-
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
15841590
GCC_PREPROCESSOR_DEFINITIONS = (
15851591
"DEBUG=1",
15861592
"$(inherited)",
@@ -1589,20 +1595,19 @@
15891595
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
15901596
PRODUCT_BUNDLE_IDENTIFIER = "com.mapbox.$(PRODUCT_NAME:rfc1034identifier)";
15911597
PRODUCT_NAME = "Geocoder (Objective-C)";
1592-
SWIFT_VERSION = 2.3;
1598+
SWIFT_VERSION = 3.0;
15931599
};
15941600
name = Debug;
15951601
};
15961602
DDC2474919A1C60E0054B0C0 /* Release */ = {
15971603
isa = XCBuildConfiguration;
15981604
baseConfigurationReference = 776DF543A8C8357F5B7A11BB /* Pods-Example (Objective-C).release.xcconfig */;
15991605
buildSettings = {
1600-
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
16011606
INFOPLIST_FILE = "Geocoder Example/Info.plist";
16021607
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
16031608
PRODUCT_BUNDLE_IDENTIFIER = "com.mapbox.$(PRODUCT_NAME:rfc1034identifier)";
16041609
PRODUCT_NAME = "Geocoder (Objective-C)";
1605-
SWIFT_VERSION = 2.3;
1610+
SWIFT_VERSION = 3.0;
16061611
};
16071612
name = Release;
16081613
};
@@ -1616,7 +1621,7 @@
16161621
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
16171622
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGeocoderTests;
16181623
PRODUCT_NAME = "$(TARGET_NAME)";
1619-
SWIFT_VERSION = 2.3;
1624+
SWIFT_VERSION = 3.0;
16201625
};
16211626
name = Debug;
16221627
};
@@ -1631,7 +1636,8 @@
16311636
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
16321637
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGeocoderTests;
16331638
PRODUCT_NAME = "$(TARGET_NAME)";
1634-
SWIFT_VERSION = 2.3;
1639+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
1640+
SWIFT_VERSION = 3.0;
16351641
};
16361642
name = Release;
16371643
};

0 commit comments

Comments
 (0)