From 63c7b02f42d82e364258e51d97d3525b874ba47f Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 26 Aug 2016 23:45:53 -0700 Subject: [PATCH 1/7] Updated library and tests for Swift 3 --- Localize_SwiftTests/Localize_SwiftTests.swift | 2 +- Sources/Localize.swift | 54 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Localize_SwiftTests/Localize_SwiftTests.swift b/Localize_SwiftTests/Localize_SwiftTests.swift index aef007b..89311ac 100644 --- a/Localize_SwiftTests/Localize_SwiftTests.swift +++ b/Localize_SwiftTests/Localize_SwiftTests.swift @@ -28,7 +28,7 @@ class Localize_SwiftTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock { + self.measure { // Put the code you want to measure the time of here. } } diff --git a/Sources/Localize.swift b/Sources/Localize.swift index 4f4b27d..b35c2c6 100644 --- a/Sources/Localize.swift +++ b/Sources/Localize.swift @@ -27,7 +27,7 @@ Swift 1.x friendly localization syntax, replaces NSLocalizedString - Parameter string: Key to be localized. - Returns: The localized string. */ -public func Localized(string: String) -> String { +public func Localized(_ string: String) -> String { return string.localized() } @@ -36,7 +36,7 @@ public func Localized(string: String) -> String { - Parameter string: Key to be localized. - Returns: The formatted localized string with arguments. */ -public func Localized(string: String, arguments: CVarArgType...) -> String { +public func Localized(_ string: String, arguments: CVarArg...) -> String { return String(format: string.localized(), arguments: arguments) } @@ -48,7 +48,7 @@ public func Localized(string: String, arguments: CVarArgType...) -> String { - returns: Pluralized localized string. */ -public func LocalizedPlural(string: String, argument: CVarArgType) -> String { +public func LocalizedPlural(_ string: String, argument: CVarArg) -> String { return string.localizedPlural(argument) } @@ -59,11 +59,13 @@ public extension String { - Returns: The localized string. */ func localized() -> String { - if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) { - return bundle.localizedStringForKey(self, value: nil, table: nil) + if let path = Bundle.main.path(forResource: Localize.currentLanguage(), ofType: "lproj"), + let bundle = Bundle(path: path) { + return bundle.localizedString(forKey: self, value: nil, table: nil) } - else if let path = NSBundle.mainBundle().pathForResource(LCLBaseBundle, ofType: "lproj"), bundle = NSBundle(path: path) { - return bundle.localizedStringForKey(self, value: nil, table: nil) + else if let path = Bundle.main.path(forResource: LCLBaseBundle, ofType: "lproj"), + let bundle = Bundle(path: path) { + return bundle.localizedString(forKey: self, value: nil, table: nil) } return self } @@ -72,7 +74,7 @@ public extension String { Swift 2 friendly localization syntax with format arguments, replaces String(format:NSLocalizedString) - Returns: The formatted localized string with arguments. */ - func localizedFormat(arguments: CVarArgType...) -> String { + func localizedFormat(_ arguments: CVarArg...) -> String { return String(format: localized(), arguments: arguments) } @@ -83,8 +85,8 @@ public extension String { - returns: Pluralized localized string. */ - func localizedPlural(argument: CVarArgType) -> String { - return NSString.localizedStringWithFormat(localized(), argument) as String + func localizedPlural(_ argument: CVarArg) -> String { + return NSString.localizedStringWithFormat(localized() as NSString, argument) as String } } @@ -92,17 +94,17 @@ public extension String { // MARK: Language Setting Functions -public class Localize: NSObject { +open class Localize: NSObject { /** List available languages - Returns: Array of available languages. */ - public class func availableLanguages(excludeBase: Bool = false) -> [String] { - var availableLanguages = NSBundle.mainBundle().localizations + open class func availableLanguages(_ excludeBase: Bool = false) -> [String] { + var availableLanguages = Bundle.main.localizations // If excludeBase = true, don't include "Base" in available languages - if let indexOfBase = availableLanguages.indexOf("Base") where excludeBase == true { - availableLanguages.removeAtIndex(indexOfBase) + if let indexOfBase = availableLanguages.index(of: "Base") , excludeBase == true { + availableLanguages.remove(at: indexOfBase) } return availableLanguages } @@ -111,8 +113,8 @@ public class Localize: NSObject { Current language - Returns: The current language. String. */ - public class func currentLanguage() -> String { - if let currentLanguage = NSUserDefaults.standardUserDefaults().objectForKey(LCLCurrentLanguageKey) as? String { + open class func currentLanguage() -> String { + if let currentLanguage = UserDefaults.standard.object(forKey: LCLCurrentLanguageKey) as? String { return currentLanguage } return defaultLanguage() @@ -122,12 +124,12 @@ public class Localize: NSObject { Change the current language - Parameter language: Desired language. */ - public class func setCurrentLanguage(language: String) { + open class func setCurrentLanguage(_ language: String) { let selectedLanguage = availableLanguages().contains(language) ? language : defaultLanguage() if (selectedLanguage != currentLanguage()){ - NSUserDefaults.standardUserDefaults().setObject(selectedLanguage, forKey: LCLCurrentLanguageKey) - NSUserDefaults.standardUserDefaults().synchronize() - NSNotificationCenter.defaultCenter().postNotificationName(LCLLanguageChangeNotification, object: nil) + UserDefaults.standard.set(selectedLanguage, forKey: LCLCurrentLanguageKey) + UserDefaults.standard.synchronize() + NotificationCenter.default.post(name: Notification.Name(rawValue: LCLLanguageChangeNotification), object: nil) } } @@ -135,9 +137,9 @@ public class Localize: NSObject { Default language - Returns: The app's default language. String. */ - public class func defaultLanguage() -> String { + open class func defaultLanguage() -> String { var defaultLanguage: String = String() - guard let preferredLanguage = NSBundle.mainBundle().preferredLocalizations.first else { + guard let preferredLanguage = Bundle.main.preferredLocalizations.first else { return LCLDefaultLanguage } let availableLanguages: [String] = self.availableLanguages() @@ -153,7 +155,7 @@ public class Localize: NSObject { /** Resets the current language to the default */ - public class func resetCurrentLanguageToDefault() { + open class func resetCurrentLanguageToDefault() { setCurrentLanguage(self.defaultLanguage()) } @@ -162,9 +164,9 @@ public class Localize: NSObject { - Parameter language: Desired language. - Returns: The localized string. */ - public class func displayNameForLanguage(language: String) -> String { + open class func displayNameForLanguage(_ language: String) -> String { let locale : NSLocale = NSLocale(localeIdentifier: currentLanguage()) - if let displayName = locale.displayNameForKey(NSLocaleLanguageCode, value: language) { + if let displayName = (locale as NSLocale).displayName(forKey: NSLocale.Key.languageCode, value: language) { return displayName } return String() From 431fd6de0cc8f7bb3b8ef5287287e9d78e7267f5 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 26 Aug 2016 23:46:15 -0700 Subject: [PATCH 2/7] Updated xcodeproj --- Localize_Swift.xcodeproj/project.pbxproj | 19 ++++++++++++++++++- .../xcschemes/Localize_Swift OSX.xcscheme | 2 +- .../xcschemes/Localize_Swift tvOS.xcscheme | 2 +- .../xcschemes/Localize_Swift watchOS.xcscheme | 2 +- .../xcschemes/Localize_Swift.xcscheme | 2 +- .../xcschemes/Localize_SwiftTests.xcscheme | 2 +- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Localize_Swift.xcodeproj/project.pbxproj b/Localize_Swift.xcodeproj/project.pbxproj index 077e5a4..fd8be13 100644 --- a/Localize_Swift.xcodeproj/project.pbxproj +++ b/Localize_Swift.xcodeproj/project.pbxproj @@ -269,14 +269,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Roy Marmelstein"; TargetAttributes = { 3433F2351C518AF7003AE34D = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; 3433F23F1C518AF7003AE34D = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; }; }; @@ -404,8 +406,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -452,8 +456,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -473,6 +479,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -484,6 +491,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 10; @@ -497,6 +505,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -504,6 +513,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 10; @@ -515,6 +525,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.roymarmelstein.Localize-Swift"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -525,6 +536,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.roymarmelstein.Localize-SwiftTests"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -535,6 +547,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.roymarmelstein.Localize-SwiftTests"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -582,6 +595,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 10; @@ -603,6 +617,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 10; @@ -622,6 +637,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 10; @@ -643,6 +659,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 10; diff --git a/Localize_Swift.xcodeproj/xcshareddata/xcschemes/Localize_Swift OSX.xcscheme b/Localize_Swift.xcodeproj/xcshareddata/xcschemes/Localize_Swift OSX.xcscheme index edee547..9582024 100644 --- a/Localize_Swift.xcodeproj/xcshareddata/xcschemes/Localize_Swift OSX.xcscheme +++ b/Localize_Swift.xcodeproj/xcshareddata/xcschemes/Localize_Swift OSX.xcscheme @@ -1,6 +1,6 @@ Date: Sat, 27 Aug 2016 00:09:55 -0700 Subject: [PATCH 3/7] Updated Travis config to use Xcode 8 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 384d983..f92059f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -osx_image: xcode7.3 +osx_image: xcode8.0 language: objective-c env: global: From dfa9bd53c615552d289ac4391ba212483642df5f Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Sat, 27 Aug 2016 11:49:13 +0300 Subject: [PATCH 4/7] Fix travis --- .travis.yml | 5 +++-- build.sh | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f92059f..6062010 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -osx_image: xcode8.0 +osx_image: xcode8 language: objective-c env: global: @@ -7,7 +7,7 @@ env: before_install: - brew update || brew update - brew outdated xctool || brew upgrade xctool - - gem install cocoapods + - gem install cocoapods -pre - xcrun simctl list install: echo "<3" env: @@ -19,3 +19,4 @@ script: ./build.sh $MODE branches: only: - master + - swift3.0 diff --git a/build.sh b/build.sh index 01c0c19..76af1ea 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/bash # **** Update me when new Xcode versions are released! **** -PLATFORM="platform=iOS Simulator,OS=9.3,name=iPhone 6s" +PLATFORM="platform=iOS Simulator,OS=10.0,name=iPhone 6s" SDK="iphonesimulator" From 1a55998e4e6ef11ac3eb2e2d53040c6e511d18f9 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Sat, 27 Aug 2016 11:53:37 +0300 Subject: [PATCH 5/7] Update travis --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6062010..219e53b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,8 @@ env: - LC_CTYPE=en_US.UTF-8 - LANG=en_US.UTF-8 before_install: - - brew update || brew update - - brew outdated xctool || brew upgrade xctool - - gem install cocoapods -pre + - brew update + - gem install cocoapods --pre - xcrun simctl list install: echo "<3" env: From 14783714088964c7ac5ed4105c5d558881a8570a Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Sat, 27 Aug 2016 12:08:50 +0300 Subject: [PATCH 6/7] Fix example --- .../Sample.xcodeproj/project.pbxproj | 15 ++++++++++++- .../xcshareddata/xcschemes/Sample.xcscheme | 2 +- .../xcschemes/SampleTests.xcscheme | 2 +- .../LanguageSwitch/Sample/AppDelegate.swift | 12 +++++----- .../Sample/ViewController.swift | 22 +++++++++---------- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/examples/LanguageSwitch/Sample.xcodeproj/project.pbxproj b/examples/LanguageSwitch/Sample.xcodeproj/project.pbxproj index 587d1df..6b30298 100644 --- a/examples/LanguageSwitch/Sample.xcodeproj/project.pbxproj +++ b/examples/LanguageSwitch/Sample.xcodeproj/project.pbxproj @@ -169,15 +169,17 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Roy Marmelstein"; TargetAttributes = { 3426FF8F1BB6AEE200E8E1BB = { CreatedOnToolsVersion = 7.0; + LastSwiftMigration = 0800; TestTargetID = 34346CFC1B7294470063FED4; }; 34346CFC1B7294470063FED4 = { CreatedOnToolsVersion = 6.4; + LastSwiftMigration = 0800; }; }; }; @@ -302,6 +304,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.SampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample"; }; name = Debug; @@ -316,6 +319,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.SampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample"; }; name = Release; @@ -324,6 +328,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -333,8 +338,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -369,6 +376,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -378,8 +386,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -398,6 +408,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.4; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -411,6 +422,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.roymarmelstein.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -423,6 +435,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.roymarmelstein.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/examples/LanguageSwitch/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme b/examples/LanguageSwitch/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme index bed8a8a..8603030 100644 --- a/examples/LanguageSwitch/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme +++ b/examples/LanguageSwitch/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme @@ -1,6 +1,6 @@ Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // 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. // 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. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // 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. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // 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. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // 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. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/examples/LanguageSwitch/Sample/ViewController.swift b/examples/LanguageSwitch/Sample/ViewController.swift index 9db4879..b96adc1 100644 --- a/examples/LanguageSwitch/Sample/ViewController.swift +++ b/examples/LanguageSwitch/Sample/ViewController.swift @@ -27,29 +27,29 @@ class ViewController: UIViewController { } // Add an observer for LCLLanguageChangeNotification on viewWillAppear. This is posted whenever a language changes and allows the viewcontroller to make the necessary UI updated. Very useful for places in your app when a language change might happen. - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - NSNotificationCenter.defaultCenter().addObserver(self, selector: "setText", name: LCLLanguageChangeNotification, object: nil) + NotificationCenter.defaultCenter().addObserver(self, selector: "setText", name: LCLLanguageChangeNotification, object: nil) } // Remove the LCLLanguageChangeNotification on viewWillDisappear - override func viewWillDisappear(animated: Bool) { + override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) - NSNotificationCenter.defaultCenter().removeObserver(self) + NotificationCenter.default.removeObserver(self) } // MARK: Localized Text func setText(){ textLabel.text = "Hello world".localized(); - changeButton.setTitle("Change".localized(), forState: UIControlState.Normal) - resetButton.setTitle("Reset".localized(), forState: UIControlState.Normal) + changeButton.setTitle("Change".localized(), for: UIControlState.Normal) + resetButton.setTitle("Reset".localized(), for: UIControlState.Normal) } // MARK: IBActions - @IBAction func doChangeLanguage(sender: AnyObject) { - actionSheet = UIAlertController(title: nil, message: "Switch Language", preferredStyle: UIAlertControllerStyle.ActionSheet) + @IBAction func doChangeLanguage(_ sender: AnyObject) { + actionSheet = UIAlertController(title: nil, message: "Switch Language", preferredStyle: UIAlertControllerStyle.actionSheet) for language in availableLanguages { let displayName = Localize.displayNameForLanguage(language) let languageAction = UIAlertAction(title: displayName, style: .Default, handler: { @@ -58,14 +58,14 @@ class ViewController: UIViewController { }) actionSheet.addAction(languageAction) } - let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { + let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (alert: UIAlertAction) -> Void in }) actionSheet.addAction(cancelAction) - self.presentViewController(actionSheet, animated: true, completion: nil) + self.present(actionSheet, animated: true, completion: nil) } - @IBAction func doResetLanguage(sender: AnyObject) { + @IBAction func doResetLanguage(_ sender: AnyObject) { Localize.resetCurrentLanguageToDefault() } } From 170db30819428a9f15896a430e0855d070b04ce5 Mon Sep 17 00:00:00 2001 From: Roy Marmelstein Date: Sat, 27 Aug 2016 12:22:56 +0300 Subject: [PATCH 7/7] Fix example --- examples/LanguageSwitch/Sample/AppDelegate.swift | 2 +- examples/LanguageSwitch/Sample/ViewController.swift | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/LanguageSwitch/Sample/AppDelegate.swift b/examples/LanguageSwitch/Sample/AppDelegate.swift index 87e08fc..fec7814 100644 --- a/examples/LanguageSwitch/Sample/AppDelegate.swift +++ b/examples/LanguageSwitch/Sample/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: Any]?) -> Bool { + private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/examples/LanguageSwitch/Sample/ViewController.swift b/examples/LanguageSwitch/Sample/ViewController.swift index b96adc1..1fb5df9 100644 --- a/examples/LanguageSwitch/Sample/ViewController.swift +++ b/examples/LanguageSwitch/Sample/ViewController.swift @@ -29,7 +29,7 @@ class ViewController: UIViewController { // Add an observer for LCLLanguageChangeNotification on viewWillAppear. This is posted whenever a language changes and allows the viewcontroller to make the necessary UI updated. Very useful for places in your app when a language change might happen. override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - NotificationCenter.defaultCenter().addObserver(self, selector: "setText", name: LCLLanguageChangeNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(rawValue: LCLLanguageChangeNotification), object: nil) } // Remove the LCLLanguageChangeNotification on viewWillDisappear @@ -42,8 +42,8 @@ class ViewController: UIViewController { func setText(){ textLabel.text = "Hello world".localized(); - changeButton.setTitle("Change".localized(), for: UIControlState.Normal) - resetButton.setTitle("Reset".localized(), for: UIControlState.Normal) + changeButton.setTitle("Change".localized(), for: UIControlState.normal) + resetButton.setTitle("Reset".localized(), for: UIControlState.normal) } // MARK: IBActions @@ -52,7 +52,7 @@ class ViewController: UIViewController { actionSheet = UIAlertController(title: nil, message: "Switch Language", preferredStyle: UIAlertControllerStyle.actionSheet) for language in availableLanguages { let displayName = Localize.displayNameForLanguage(language) - let languageAction = UIAlertAction(title: displayName, style: .Default, handler: { + let languageAction = UIAlertAction(title: displayName, style: .default, handler: { (alert: UIAlertAction!) -> Void in Localize.setCurrentLanguage(language) })