Skip to content

Commit 5a163e1

Browse files
committed
swift 2.0
1 parent 001eb20 commit 5a163e1

File tree

13 files changed

+85
-73
lines changed

13 files changed

+85
-73
lines changed

CFCityPickerVC.xcodeproj/project.pbxproj

+8-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@
288288
89F162361B68D4B7005556C3 /* Project object */ = {
289289
isa = PBXProject;
290290
attributes = {
291-
LastUpgradeCheck = 0630;
291+
LastSwiftMigration = 0700;
292+
LastSwiftUpdateCheck = 0700;
293+
LastUpgradeCheck = 0700;
292294
ORGANIZATIONNAME = "冯成林";
293295
TargetAttributes = {
294296
89F1623D1B68D4B8005556C3 = {
@@ -432,6 +434,7 @@
432434
COPY_PHASE_STRIP = NO;
433435
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
434436
ENABLE_STRICT_OBJC_MSGSEND = YES;
437+
ENABLE_TESTABILITY = YES;
435438
GCC_C_LANGUAGE_STANDARD = gnu99;
436439
GCC_DYNAMIC_NO_PIC = NO;
437440
GCC_NO_COMMON_BLOCKS = YES;
@@ -500,6 +503,7 @@
500503
INFOPLIST_FILE = CFCityPickerVC/Info.plist;
501504
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
502505
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
506+
PRODUCT_BUNDLE_IDENTIFIER = "HM.$(PRODUCT_NAME:rfc1034identifier)";
503507
PRODUCT_NAME = "$(TARGET_NAME)";
504508
};
505509
name = Debug;
@@ -512,6 +516,7 @@
512516
INFOPLIST_FILE = CFCityPickerVC/Info.plist;
513517
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
514518
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
519+
PRODUCT_BUNDLE_IDENTIFIER = "HM.$(PRODUCT_NAME:rfc1034identifier)";
515520
PRODUCT_NAME = "$(TARGET_NAME)";
516521
};
517522
name = Release;
@@ -530,6 +535,7 @@
530535
);
531536
INFOPLIST_FILE = CFCityPickerVCTests/Info.plist;
532537
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
538+
PRODUCT_BUNDLE_IDENTIFIER = "HM.$(PRODUCT_NAME:rfc1034identifier)";
533539
PRODUCT_NAME = "$(TARGET_NAME)";
534540
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CFCityPickerVC.app/CFCityPickerVC";
535541
};
@@ -545,6 +551,7 @@
545551
);
546552
INFOPLIST_FILE = CFCityPickerVCTests/Info.plist;
547553
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
554+
PRODUCT_BUNDLE_IDENTIFIER = "HM.$(PRODUCT_NAME:rfc1034identifier)";
548555
PRODUCT_NAME = "$(TARGET_NAME)";
549556
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CFCityPickerVC.app/CFCityPickerVC";
550557
};

CFCityPickerVC.xcodeproj/xcuserdata/Charlin.xcuserdatad/xcschemes/CFCityPickerVC.xcscheme

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0630"
3+
LastUpgradeVersion = "0700"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -37,10 +37,10 @@
3737
</BuildActionEntries>
3838
</BuildAction>
3939
<TestAction
40+
buildConfiguration = "Debug"
4041
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4142
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
42-
shouldUseLaunchSchemeArgsEnv = "YES"
43-
buildConfiguration = "Debug">
43+
shouldUseLaunchSchemeArgsEnv = "YES">
4444
<Testables>
4545
<TestableReference
4646
skipped = "NO">
@@ -62,15 +62,18 @@
6262
ReferencedContainer = "container:CFCityPickerVC.xcodeproj">
6363
</BuildableReference>
6464
</MacroExpansion>
65+
<AdditionalOptions>
66+
</AdditionalOptions>
6567
</TestAction>
6668
<LaunchAction
69+
buildConfiguration = "Debug"
6770
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
6871
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
6972
launchStyle = "0"
7073
useCustomWorkingDirectory = "NO"
71-
buildConfiguration = "Debug"
7274
ignoresPersistentStateOnLaunch = "NO"
7375
debugDocumentVersioning = "YES"
76+
debugServiceExtension = "internal"
7477
allowLocationSimulation = "YES">
7578
<BuildableProductRunnable
7679
runnableDebuggingMode = "0">
@@ -86,10 +89,10 @@
8689
</AdditionalOptions>
8790
</LaunchAction>
8891
<ProfileAction
92+
buildConfiguration = "Release"
8993
shouldUseLaunchSchemeArgsEnv = "YES"
9094
savedToolIdentifier = ""
9195
useCustomWorkingDirectory = "NO"
92-
buildConfiguration = "Release"
9396
debugDocumentVersioning = "YES">
9497
<BuildableProductRunnable
9598
runnableDebuggingMode = "0">

CFCityPickerVC/CFCityPickerVC/CFCityPickerVC.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CFCityPickerVC: UIViewController {
4848
var currentCityItemView: HeaderItemView!
4949

5050
deinit{
51-
println("控制器安全释放")
51+
print("控制器安全释放")
5252
}
5353

5454
var tableView: UITableView!

CFCityPickerVC/CFCityPickerVC/Common/LocationManager.swift

+40-38
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum GeoCodingType{
4040
case ReverseGeocoding
4141
}
4242

43+
4344
class LocationManager: NSObject,CLLocationManagerDelegate {
4445

4546
/* Private variables */
@@ -55,7 +56,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
5556
private let verboseMessageDictionary = [CLAuthorizationStatus.NotDetermined:NSLocalizedString("You have not yet made a choice with regards to this application.", comment: ""),
5657
CLAuthorizationStatus.Restricted:NSLocalizedString("This application is not authorized to use location services. Due to active restrictions on location services, the user cannot change this status, and may not have personally denied authorization.", comment: ""),
5758
CLAuthorizationStatus.Denied:NSLocalizedString("You have explicitly denied authorization for this application, or location services are disabled in Settings.", comment: ""),
58-
CLAuthorizationStatus.AuthorizedAlways:NSLocalizedString("App is Authorized to always use location services.", comment: ""),CLAuthorizationStatus.AuthorizedWhenInUse:NSLocalizedString("You have granted authorization to use your location only when the app is visible to you.", comment: "")]
59+
]
5960

6061

6162
var delegate:LocationManagerDelegate? = nil
@@ -160,7 +161,9 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
160161
if NSString(string: UIDevice.currentDevice().systemVersion).doubleValue >= 8 {
161162

162163
//locationManager.requestAlwaysAuthorization() // add in plist NSLocationAlwaysUsageDescription
163-
locationManager.requestWhenInUseAuthorization() // add in plist NSLocationWhenInUseUsageDescription
164+
if #available(iOS 8.0, *) {
165+
locationManager.requestWhenInUseAuthorization()
166+
}
164167
}
165168

166169
startLocationManger()
@@ -192,7 +195,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
192195
isRunning = false
193196
}
194197

195-
internal func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
198+
internal func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
196199

197200
stopLocationManger()
198201

@@ -213,7 +216,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
213216
}
214217
}
215218

216-
internal func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
219+
internal func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
217220

218221
let arrayOfLocation = locations as NSArray
219222
let location = arrayOfLocation.lastObject as! CLLocation
@@ -252,10 +255,10 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
252255
}
253256
}
254257

255-
internal func locationManager(manager: CLLocationManager!,
258+
internal func locationManager(manager: CLLocationManager,
256259
didChangeAuthorizationStatus status: CLAuthorizationStatus) {
257260
var hasAuthorised = false
258-
var verboseKey = status
261+
let verboseKey = status
259262
switch status {
260263
case CLAuthorizationStatus.Restricted:
261264
locationStatus = NSLocalizedString("Restricted Access", comment: "")
@@ -298,7 +301,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
298301
}
299302
}
300303

301-
func reverseGeocodeLocationWithLatLon(#latitude:Double, longitude: Double,onReverseGeocodingCompletionHandler:LMReverseGeocodeCompletionHandler){
304+
func reverseGeocodeLocationWithLatLon(latitude latitude:Double, longitude: Double,onReverseGeocodingCompletionHandler:LMReverseGeocodeCompletionHandler){
302305

303306
let location:CLLocation = CLLocation(latitude:latitude, longitude: longitude)
304307

@@ -319,11 +322,11 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
319322
geocoder.reverseGeocodeLocation(location, completionHandler: {(placemarks, error)->Void in
320323

321324
if error != nil {
322-
self.reverseGeocodingCompletionHandler!(reverseGecodeInfo:nil,placemark:nil, error: error.localizedDescription)
325+
self.reverseGeocodingCompletionHandler!(reverseGecodeInfo:nil,placemark:nil, error: error!.localizedDescription)
323326
} else {
324327

325-
if let placemark = placemarks?[0] as? CLPlacemark {
326-
var address = AddressParser()
328+
if let placemark = placemarks?[0]{
329+
let address = AddressParser()
327330
address.parseAppleLocationData(placemark)
328331
let addressDict = address.getAddressDictionary()
329332
self.reverseGeocodingCompletionHandler!(reverseGecodeInfo: addressDict,placemark:placemark,error: nil)
@@ -335,7 +338,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
335338
})
336339
}
337340

338-
func geocodeAddressString(#address:NSString, onGeocodingCompletionHandler:LMGeocodeCompletionHandler){
341+
func geocodeAddressString(address address:NSString, onGeocodingCompletionHandler:LMGeocodeCompletionHandler){
339342

340343
self.geocodingCompletionHandler = onGeocodingCompletionHandler
341344

@@ -345,14 +348,15 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
345348
private func geoCodeAddress(address:NSString){
346349

347350
let geocoder = CLGeocoder()
348-
geocoder.geocodeAddressString(address as String, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in
351+
352+
geocoder.geocodeAddressString(address as String, completionHandler: {(placemarks, error) -> Void in
349353

350354
if error != nil {
351355

352-
self.geocodingCompletionHandler!(gecodeInfo:nil,placemark:nil,error: error.localizedDescription)
356+
self.geocodingCompletionHandler!(gecodeInfo:nil,placemark:nil,error: error!.localizedDescription)
353357
} else {
354-
if let placemark = placemarks?[0] as? CLPlacemark {
355-
var address = AddressParser()
358+
if let placemark = placemarks?[0]{
359+
let address = AddressParser()
356360
address.parseAppleLocationData(placemark)
357361
let addressDict = address.getAddressDictionary()
358362
self.geocodingCompletionHandler!(gecodeInfo: addressDict,placemark:placemark,error: nil)
@@ -363,7 +367,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
363367
})
364368
}
365369

366-
func geocodeUsingGoogleAddressString(#address:NSString, onGeocodingCompletionHandler:LMGeocodeCompletionHandler){
370+
func geocodeUsingGoogleAddressString(address address:NSString, onGeocodingCompletionHandler:LMGeocodeCompletionHandler){
367371

368372
self.geocodingCompletionHandler = onGeocodingCompletionHandler
369373

@@ -379,7 +383,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
379383
performOperationForURL(urlString, type: GeoCodingType.Geocoding)
380384
}
381385

382-
func reverseGeocodeLocationUsingGoogleWithLatLon(#latitude:Double, longitude: Double,onReverseGeocodingCompletionHandler:LMReverseGeocodeCompletionHandler){
386+
func reverseGeocodeLocationUsingGoogleWithLatLon(latitude latitude:Double, longitude: Double,onReverseGeocodingCompletionHandler:LMReverseGeocodeCompletionHandler){
383387

384388
self.reverseGeocodingCompletionHandler = onReverseGeocodingCompletionHandler
385389

@@ -391,7 +395,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
391395
reverseGeocodeLocationUsingGoogleWithLatLon(latitude: coord.coordinate.latitude, longitude: coord.coordinate.longitude, onReverseGeocodingCompletionHandler: onReverseGeocodingCompletionHandler)
392396
}
393397

394-
private func reverseGocodeUsingGoogle(#latitude:Double, longitude: Double){
398+
private func reverseGocodeUsingGoogle(latitude latitude:Double, longitude: Double){
395399

396400
var urlString = "http://maps.googleapis.com/maps/api/geocode/json?latlng=\(latitude),\(longitude)" as NSString
397401

@@ -412,7 +416,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
412416

413417
if error != nil {
414418

415-
self.setCompletionHandler(responseInfo:nil, placemark:nil, error:error.localizedDescription, type:type)
419+
self.setCompletionHandler(responseInfo:nil, placemark:nil, error:error!.localizedDescription, type:type)
416420
} else {
417421

418422
let kStatus = "status"
@@ -422,10 +426,8 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
422426
let kRequestDenied = "REQUEST_DENIED"
423427
let kInvalidRequest = "INVALID_REQUEST"
424428
let kInvalidInput = "Invalid Input"
425-
426-
let dataAsString: NSString? = NSString(data: data, encoding: NSUTF8StringEncoding)
427-
428-
let jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
429+
430+
let jsonResult: NSDictionary = (try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)) as! NSDictionary
429431

430432
var status = jsonResult.valueForKey(kStatus) as! NSString
431433
status = status.lowercaseString
@@ -453,7 +455,7 @@ class LocationManager: NSObject,CLLocationManagerDelegate {
453455
})
454456
}
455457

456-
private func setCompletionHandler(#responseInfo:NSDictionary?,placemark:CLPlacemark?, error:String?,type:GeoCodingType){
458+
private func setCompletionHandler(responseInfo responseInfo:NSDictionary?,placemark:CLPlacemark?, error:String?,type:GeoCodingType){
457459

458460
if type == GeoCodingType.Geocoding {
459461
self.geocodingCompletionHandler!(gecodeInfo:responseInfo,placemark:placemark,error:error)
@@ -499,7 +501,7 @@ private class AddressParser: NSObject{
499501

500502
private func getAddressDictionary()-> NSDictionary {
501503

502-
var addressDict = NSMutableDictionary()
504+
let addressDict = NSMutableDictionary()
503505

504506
addressDict.setValue(latitude, forKey: "latitude")
505507
addressDict.setValue(longitude, forKey: "longitude")
@@ -516,17 +518,17 @@ private class AddressParser: NSObject{
516518

517519
private func parseAppleLocationData(placemark:CLPlacemark) {
518520

519-
var addressLines = placemark.addressDictionary["FormattedAddressLines"] as! NSArray
521+
var addressLines = placemark.addressDictionary?["FormattedAddressLines"] as! NSArray
520522

521523
//self.streetNumber = placemark.subThoroughfare ? placemark.subThoroughfare : ""
522-
self.streetNumber = placemark.thoroughfare != nil ? placemark.thoroughfare : ""
523-
self.locality = placemark.locality != nil ? placemark.locality : ""
524-
self.postalCode = placemark.postalCode != nil ? placemark.postalCode : ""
525-
self.subLocality = placemark.subLocality != nil ? placemark.subLocality : ""
526-
self.administrativeArea = placemark.administrativeArea != nil ? placemark.administrativeArea : ""
527-
self.country = placemark.country != nil ? placemark.country : ""
528-
self.longitude = placemark.location.coordinate.longitude.description;
529-
self.latitude = placemark.location.coordinate.latitude.description
524+
self.streetNumber = (placemark.thoroughfare != nil ? placemark.thoroughfare : "")!
525+
self.locality = (placemark.locality != nil ? placemark.locality : "")!
526+
self.postalCode = (placemark.postalCode != nil ? placemark.postalCode : "")!
527+
self.subLocality = (placemark.subLocality != nil ? placemark.subLocality : "")!
528+
self.administrativeArea = placemark.administrativeArea != nil ? (placemark.administrativeArea)! : ""
529+
self.country = placemark.country != nil ? placemark.country! : ""
530+
self.longitude = placemark.location!.coordinate.longitude.description;
531+
self.latitude = placemark.location!.coordinate.latitude.description
530532
if addressLines.count>0 {
531533
self.formattedAddress = addressLines.componentsJoinedByString(", ")
532534
} else {
@@ -569,8 +571,8 @@ private class AddressParser: NSObject{
569571

570572
let index:NSInteger = inArray.indexOfObjectPassingTest { (obj, idx, stop) -> Bool in
571573

572-
var objDict:NSDictionary = obj as! NSDictionary
573-
var types:NSArray = objDict.objectForKey("types") as! NSArray
574+
let objDict:NSDictionary = obj as! NSDictionary
575+
let types:NSArray = objDict.objectForKey("types") as! NSArray
574576
let type = types.firstObject as! NSString
575577
return type.isEqualToString(component as String)
576578
}
@@ -583,7 +585,7 @@ private class AddressParser: NSObject{
583585
return ""
584586
}
585587

586-
var type = ((inArray.objectAtIndex(index) as! NSDictionary).valueForKey(ofType as String)!) as! NSString
588+
let type = ((inArray.objectAtIndex(index) as! NSDictionary).valueForKey(ofType as String)!) as! NSString
587589

588590
if type.length > 0 {
589591

@@ -632,7 +634,7 @@ private class AddressParser: NSObject{
632634
var lng = self.longitude.doubleValue
633635
var coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lng)
634636

635-
var placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDict as [NSObject : AnyObject])
637+
var placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDict as! [String : AnyObject])
636638

637639
return (placemark as CLPlacemark)
638640
}

CFCityPickerVC/CFCityPickerVC/Controller/CitySearchResultVC.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension CitySearchResultVC{
5858
}
5959

6060

61-
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
61+
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
6262
touchBeganAction?()
6363
}
6464

0 commit comments

Comments
 (0)