Skip to content

Commit

Permalink
Swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
shu223 committed Apr 11, 2019
1 parent a53f216 commit 4c2601f
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 33 deletions.
16 changes: 6 additions & 10 deletions iOS-10-Sampler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1260,13 +1260,13 @@
8AB430541D7A6B4900A3BD98 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = 9Z86A4AWDE;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
8AB430681D7A6B4A00A3BD98 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = 9Z86A4AWDE;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
TestTargetID = 8AB430541D7A6B4900A3BD98;
};
Expand Down Expand Up @@ -1777,8 +1777,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.shu223.iOS-10-Sampler";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "iOS-10-Sampler/iOS10Sampler-Bridging-Header.h";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -1792,8 +1791,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.shu223.iOS-10-Sampler";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "iOS-10-Sampler/iOS10Sampler-Bridging-Header.h";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -1807,8 +1805,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.shu223.iOS-10-SamplerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOS-10-Sampler.app/iOS-10-Sampler";
};
name = Debug;
Expand All @@ -1823,8 +1820,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.shu223.iOS-10-SamplerTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOS-10-Sampler.app/iOS-10-Sampler";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion iOS-10-Sampler/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
4 changes: 2 additions & 2 deletions iOS-10-Sampler/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class RootViewController: UITableViewController {
// MARK: UITableViewDelegate

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
return UITableView.automaticDimension
}

override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
return UITableView.automaticDimension
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AttributedSpeechViewController: UIViewController {

attributedStr = NSMutableAttributedString(string: baseStr)
let rangeAll = NSMakeRange(0, baseStr.count)
attributedStr.addAttribute(NSAttributedStringKey(rawValue: AVSpeechSynthesisIPANotationAttribute), value: "tən.tən.mi", range: rangeAll)
attributedStr.addAttribute(NSAttributedString.Key(rawValue: AVSpeechSynthesisIPANotationAttribute), value: "tən.tən.mi", range: rangeAll)
updateUtterance(attributed: false)
}

Expand Down
4 changes: 2 additions & 2 deletions iOS-10-Sampler/Samples/HapticViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class HapticViewController: UIViewController {
}

@IBAction func impactBtnTapped(_ sender: UIButton) {
guard let style = UIImpactFeedbackStyle(rawValue: sender.tag) else {fatalError()}
guard let style = UIImpactFeedbackGenerator.FeedbackStyle(rawValue: sender.tag) else {fatalError()}
impactFeedbacker = UIImpactFeedbackGenerator(style: style)
impactFeedbacker.prepare()
impactFeedbacker.impactOccurred()
}

@IBAction func notificationBtnTapped(_ sender: UIButton) {
guard let type = UINotificationFeedbackType(rawValue: sender.tag) else {fatalError()}
guard let type = UINotificationFeedbackGenerator.FeedbackType(rawValue: sender.tag) else {fatalError()}
notificationFeedbacker.notificationOccurred(type)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class PersitentContainerViewController: UITableViewController {
return true
}

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
switch editingStyle {
case .delete:
delete(at: indexPath.row)
Expand Down
13 changes: 10 additions & 3 deletions iOS-10-Sampler/Samples/SpeechRecognitionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class SpeechRecognitionViewController: UIViewController, SFSpeechRecognizerDeleg
case .notDetermined:
self.recordBtn.isEnabled = false
self.recordBtn.setTitle("Speech recognition not yet authorized", for: .disabled)
@unknown default:
fatalError()
}
}
}
Expand All @@ -82,9 +84,9 @@ class SpeechRecognitionViewController: UIViewController, SFSpeechRecognizerDeleg
}

let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSessionCategoryRecord)
try audioSession.setMode(AVAudioSessionModeMeasurement)
try audioSession.setActive(true, with: .notifyOthersOnDeactivation)
try audioSession.setCategory(AVAudioSession.Category(rawValue: convertFromAVAudioSessionCategory(AVAudioSession.Category.record)))
try audioSession.setMode(AVAudioSession.Mode.measurement)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)

recognitionRequest = SFSpeechAudioBufferRecognitionRequest()

Expand Down Expand Up @@ -179,3 +181,8 @@ class SpeechRecognitionViewController: UIViewController, SFSpeechRecognizerDeleg
}
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromAVAudioSessionCategory(_ input: AVAudioSession.Category) -> String {
return input.rawValue
}
7 changes: 6 additions & 1 deletion iOS-10-Sampler/Samples/StickerPackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class StickerPackViewController: UIViewController {

@IBAction func openBtnTapped(sender: UIButton) {
let url = URL(string: "sms:")!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
UIApplication.shared.open(url, options: convertToUIApplicationOpenExternalURLOptionsKeyDictionary([:]), completionHandler: nil)
}

}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToUIApplicationOpenExternalURLOptionsKeyDictionary(_ input: [String: Any]) -> [UIApplication.OpenExternalURLOptionsKey: Any] {
return Dictionary(uniqueKeysWithValues: input.map { key, value in (UIApplication.OpenExternalURLOptionsKey(rawValue: key), value)})
}
14 changes: 10 additions & 4 deletions iOS-10-Sampler/Samples/TabBadgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class TabBadgeViewController: UIViewController, UITabBarDelegate {
shadow.shadowColor = #colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1)
shadow.shadowOffset = CGSize(width: 1, height: 1)
shadow.shadowBlurRadius = 3
let attributes: [String : Any] = [NSAttributedStringKey.font.rawValue: UIFont(name: "Menlo-Bold", size: 30)!,
NSAttributedStringKey.foregroundColor.rawValue: #colorLiteral(red: 0.9098039269, green: 0.4784313738, blue: 0.6431372762, alpha: 1),
NSAttributedStringKey.shadow.rawValue: shadow]
let attributes: [String : Any] = [NSAttributedString.Key.font.rawValue: UIFont(name: "Menlo-Bold", size: 30)!,
NSAttributedString.Key.foregroundColor.rawValue: #colorLiteral(red: 0.9098039269, green: 0.4784313738, blue: 0.6431372762, alpha: 1),
NSAttributedString.Key.shadow.rawValue: shadow]
// New!
item.setBadgeTextAttributes(attributes, for: .normal)
item.setBadgeTextAttributes(convertToOptionalNSAttributedStringKeyDictionary(attributes), for: .normal)

// New!
item.badgeColor = UIColor.clear
Expand Down Expand Up @@ -62,3 +62,9 @@ class TabBadgeViewController: UIViewController, UITabBarDelegate {
}
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertToOptionalNSAttributedStringKeyDictionary(_ input: [String: Any]?) -> [NSAttributedString.Key: Any]? {
guard let input = input else { return nil }
return Dictionary(uniqueKeysWithValues: input.map { key, value in (NSAttributedString.Key(rawValue: key), value)})
}
10 changes: 5 additions & 5 deletions iOS-10-Sampler/Samples/UserNotificationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class UserNotificationViewController: UIViewController, UNUserNotificationCenter
// Build content
content.title = "iOS-10-Sampler"
content.body = "This is the body."
content.sound = UNNotificationSound.default()
content.sound = UNNotificationSound.default
content.attachments = [movieAttachment]

// Initializa request
Expand Down Expand Up @@ -67,11 +67,11 @@ class UserNotificationViewController: UIViewController, UNUserNotificationCenter
// =========================================================================
// MARK: - UNNotificationCenterDelegate

private func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
internal func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
print("\(self.classForCoder)/" + #function)
}

private func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
internal func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
print("\(self.classForCoder)/" + #function)
}

Expand All @@ -88,10 +88,10 @@ class UserNotificationViewController: UIViewController, UNUserNotificationCenter
let alert = UIAlertController(
title: "Close this app",
message: "A local notification has been scheduled. Close this app and wait 10 sec.",
preferredStyle: UIAlertControllerStyle.alert)
preferredStyle: UIAlertController.Style.alert)
let okAction = UIAlertAction(
title: "OK",
style: UIAlertActionStyle.cancel,
style: UIAlertAction.Style.cancel,
handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true, completion: nil)
Expand Down
4 changes: 2 additions & 2 deletions libs/VideoCapture/AVCaptureDevice+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ extension AVCaptureDevice {
activeFormat = selectedFormat

if let preferredFps = preferredSpec.fps {
activeVideoMinFrameDuration = CMTimeMake(1, preferredFps)
activeVideoMaxFrameDuration = CMTimeMake(1, preferredFps)
activeVideoMinFrameDuration = CMTimeMake(value: 1, timescale: preferredFps)
activeVideoMaxFrameDuration = CMTimeMake(value: 1, timescale: preferredFps)
unlockForConfiguration()
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/VideoCapture/VideoCapture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class VideoCapture: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate, AVCa
if let previewContainer = previewContainer {
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = previewContainer.bounds
previewLayer.contentsGravity = kCAGravityResizeAspectFill
previewLayer.contentsGravity = CALayerContentsGravity.resizeAspectFill
previewLayer.videoGravity = .resizeAspectFill
previewContainer.insertSublayer(previewLayer, at: 0)
self.previewLayer = previewLayer
Expand Down

0 comments on commit 4c2601f

Please sign in to comment.