From 4388112a1b30a6c368891a44a6f736264fae5c0a Mon Sep 17 00:00:00 2001 From: banjun Date: Mon, 6 Jul 2020 23:32:55 +0900 Subject: [PATCH 1/2] migrate to Swift 5 with Xcode 11.5 --- LoveLiver-osx/AVKitExtension.swift | 4 +- LoveLiver-osx/AppDelegate.swift | 4 +- .../LivePhotoSandboxViewController.swift | 49 ++++++++++--------- LoveLiver-osx/MovieDocument.swift | 2 +- .../MovieDocumentViewController.swift | 2 +- LoveLiver-osx/MovieOverviewControl.swift | 16 +++--- .../MovieOverviewViewController.swift | 4 +- .../OverviewTouchBarItemProvider.swift | 14 +++--- LoveLiver.xcodeproj/project.pbxproj | 36 ++++++++++++-- .../xcschemes/LoveLiver-osx.xcscheme | 10 ++-- LoveLiver/JPEG.swift | 4 +- LoveLiver/QuickTimeMov.swift | 30 ++++++------ Podfile.lock | 16 +++--- 13 files changed, 110 insertions(+), 81 deletions(-) diff --git a/LoveLiver-osx/AVKitExtension.swift b/LoveLiver-osx/AVKitExtension.swift index 147cc9b..53d35f4 100644 --- a/LoveLiver-osx/AVKitExtension.swift +++ b/LoveLiver-osx/AVKitExtension.swift @@ -45,10 +45,10 @@ extension AVAssetImageGenerator { extension AVPlayerItem { var naturalSize: CGSize? { - return asset.tracks(withMediaType: AVMediaTypeVideo).first?.naturalSize + return asset.tracks(withMediaType: .video).first?.naturalSize } var minFrameDuration: CMTime? { - return asset.tracks(withMediaType: AVMediaTypeVideo).first?.minFrameDuration + return asset.tracks(withMediaType: .video).first?.minFrameDuration } } diff --git a/LoveLiver-osx/AppDelegate.swift b/LoveLiver-osx/AppDelegate.swift index 1b92340..86322e5 100644 --- a/LoveLiver-osx/AppDelegate.swift +++ b/LoveLiver-osx/AppDelegate.swift @@ -20,8 +20,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { return true } - @objc fileprivate func openDocument(_ sender: AnyObject?) { - NSDocumentController.shared().openDocument(sender) + @objc private func openDocument(_ sender: AnyObject?) { + NSDocumentController.shared.openDocument(sender) } } diff --git a/LoveLiver-osx/LivePhotoSandboxViewController.swift b/LoveLiver-osx/LivePhotoSandboxViewController.swift index 464f91a..94733d2 100644 --- a/LoveLiver-osx/LivePhotoSandboxViewController.swift +++ b/LoveLiver-osx/LivePhotoSandboxViewController.swift @@ -16,8 +16,9 @@ import Ikemen private let livePhotoDuration: TimeInterval = 3 private let outputDir = URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Pictures/LoveLiver") -fileprivate extension NSTouchBarItemIdentifier { - static let overview = NSTouchBarItemIdentifier("jp.mzp.loveliver.overview") +@available (OSX 10.12.2, *) +fileprivate extension NSTouchBarItem.Identifier { + static let overview = NSTouchBarItem.Identifier("jp.mzp.loveliver.overview") } private func label() -> NSTextField { @@ -26,7 +27,7 @@ private func label() -> NSTextField { tf.isEditable = false tf.drawsBackground = false tf.textColor = NSColor.gray - tf.font = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: NSFontWeightRegular) + tf.font = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: .regular) } } @@ -46,7 +47,7 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { b.target = self b.action = #selector(self.close) } - var closeAction: ((Void) -> Void)? + var closeAction: (() -> Void)? fileprivate func updateButtons() { exportButton.isEnabled = (exportSession == nil) @@ -120,9 +121,9 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { endLabel.stringValue = endTime.stringInmmssSS } fileprivate func updateScope() { - let duration = player.currentItem?.duration ?? kCMTimeZero + let duration = player.currentItem?.duration ?? .zero - if CMTimeMaximum(kCMTimeZero, startTime) == kCMTimeZero { + if CMTimeMaximum(.zero, startTime) == .zero { // scope is clipped by zero. underflow scope start by subtracting from end scopeRange = CMTimeRange(start: CMTimeSubtract(endTime, CMTime(seconds: livePhotoDuration, preferredTimescale: posterTime.timescale)), end: endTime) } else if CMTimeMinimum(duration, endTime) == duration { @@ -138,23 +139,23 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { let item = AVPlayerItem(asset: asset) self.baseFilename = baseFilename - posterTime = CMTimeConvertScale(player.currentTime(), max(600, player.currentTime().timescale), .default) // timescale = 1 (too inaccurate) when posterTime = 0 + posterTime = CMTimeConvertScale(player.currentTime(), timescale: max(600, player.currentTime().timescale), method: .default) // timescale = 1 (too inaccurate) when posterTime = 0 let duration = item.duration let offset = CMTime(seconds: livePhotoDuration / 2, preferredTimescale: posterTime.timescale) - startTime = CMTimeMaximum(kCMTimeZero, CMTimeSubtract(posterTime, offset)) + startTime = CMTimeMaximum(.zero, CMTimeSubtract(posterTime, offset)) endTime = CMTimeMinimum(CMTimeAdd(posterTime, offset), duration) self.player = AVPlayer(playerItem: item) imageGenerator = AVAssetImageGenerator(asset: asset) ※ { g -> Void in - g.requestedTimeToleranceBefore = kCMTimeZero - g.requestedTimeToleranceAfter = kCMTimeZero + g.requestedTimeToleranceBefore = .zero + g.requestedTimeToleranceAfter = .zero g.maximumSize = CGSize(width: 128 * 2, height: 128 * 2) } overview = MovieOverviewControl(player: self.player, playerItem: item) overview.draggingMode = .scope - overview.imageGeneratorTolerance = kCMTimeZero + overview.imageGeneratorTolerance = .zero if #available(OSX 10.12.2, *) { touchBarItemProvider = OverviewTouchBarItemProvider(player: self.player, playerItem: item) @@ -261,8 +262,8 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { func onScopeChange(_ overview : MovieOverviewControl) { guard let s = overview.scopeRange?.start, let e = overview.scopeRange?.end else { return } - startTime = CMTimeMaximum(kCMTimeZero, s) - endTime = CMTimeMinimum(player.currentItem?.duration ?? kCMTimeZero, e) + startTime = CMTimeMaximum(.zero, s) + endTime = CMTimeMinimum(player.currentItem?.duration ?? .zero, e) if !((touchBarItemProvider?.dragging ?? false) || self.overview.dragging) { updateImages() @@ -272,8 +273,8 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { @objc fileprivate func export() { guard let asset = player.currentItem?.asset else { return } let imageGenerator = AVAssetImageGenerator(asset: asset) ※ { - $0.requestedTimeToleranceBefore = kCMTimeZero - $0.requestedTimeToleranceAfter = kCMTimeZero + $0.requestedTimeToleranceBefore = .zero + $0.requestedTimeToleranceAfter = .zero } guard let image = imageGenerator.copyImage(at: posterTime) else { return } guard let _ = try? FileManager.default.createDirectory(atPath: outputDir.path, withIntermediateDirectories: true, attributes: nil) else { return } @@ -297,7 +298,7 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { guard let _ = try? image.tiffRepresentation?.write(to: URL(fileURLWithPath: tmpImagePath), options: [.atomic]) else { return } // create AVAssetExportSession each time because it cannot be reused after export completion guard let session = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetPassthrough) else { return } - session.outputFileType = "com.apple.quicktime-movie" + session.outputFileType = .mov session.outputURL = URL(fileURLWithPath: tmpMoviePath) session.timeRange = CMTimeRange(start: startTime, end: endTime) session.exportAsynchronously { @@ -312,6 +313,8 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { self.showInFinderAndOpenInPhotos([imagePath, moviePath].map{URL(fileURLWithPath: $0)}) case .cancelled, .exporting, .failed, .unknown, .waiting: + fallthrough + @unknown default: NSLog("%@", "exportAsynchronouslyWithCompletionHandler = \(session.status)") } @@ -327,22 +330,22 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { } fileprivate func showInFinderAndOpenInPhotos(_ fileURLs: [URL]) { - NSWorkspace.shared().activateFileViewerSelecting(fileURLs) + NSWorkspace.shared.activateFileViewerSelecting(fileURLs) // wait until Finder is active or timed out, // to avoid openURLs overtaking Finder activation DispatchQueue.global(qos: .default).async { let start = Date() - while NSWorkspace.shared().frontmostApplication?.bundleIdentifier != "com.apple.finder" && Date().timeIntervalSince(start) < 5 { + while NSWorkspace.shared.frontmostApplication?.bundleIdentifier != "com.apple.finder" && Date().timeIntervalSince(start) < 5 { Thread.sleep(forTimeInterval: 0.1) } - NSWorkspace.shared().open(fileURLs, withAppBundleIdentifier: "com.apple.Photos", options: [], additionalEventParamDescriptor: nil, launchIdentifiers: nil) + NSWorkspace.shared.open(fileURLs, withAppBundleIdentifier: "com.apple.Photos", options: [], additionalEventParamDescriptor: nil, launchIdentifiers: nil) } } private func shouldUpdateScopeRange(scopeRange : CMTimeRange?) -> Bool { guard let scopeRange = scopeRange else { return false } - return CMTimeRangeContainsTime(scopeRange, self.posterTime) + return CMTimeRangeContainsTime(scopeRange, time: self.posterTime) } @objc fileprivate func close() { @@ -350,7 +353,7 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { } @objc fileprivate func play() { - player.seek(to: startTime, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero) + player.seek(to: startTime, toleranceBefore: .zero, toleranceAfter: .zero) player.play() } @@ -371,7 +374,7 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { case (is AVPlayer, _): let stopped = (player.rate == 0) if stopped { - player.seek(to: posterTime, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero) + player.seek(to: posterTime, toleranceBefore: .zero, toleranceAfter: .zero) } break default: @@ -380,7 +383,7 @@ class LivePhotoSandboxViewController: NSViewController, NSTouchBarDelegate { } @available(OSX 10.12.2, *) - func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem? { + func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? { if identifier == .overview { return touchBarItemProvider?.makeTouchbarItem(identifier: identifier) } else { diff --git a/LoveLiver-osx/MovieDocument.swift b/LoveLiver-osx/MovieDocument.swift index 8c066ac..3ef1019 100644 --- a/LoveLiver-osx/MovieDocument.swift +++ b/LoveLiver-osx/MovieDocument.swift @@ -58,7 +58,7 @@ class MovieDocument: NSDocument, NSWindowDelegate { overviewVC = MovieOverviewViewController(player: player!, playerItem: playerItem!) overviewWindow = NSWindow(contentViewController: overviewVC!) ※ { w in w.delegate = self - w.styleMask = NSResizableWindowMask + w.styleMask = .resizable } addWindowController(NSWindowController(window: overviewWindow)) mainWindow!.addChildWindow(overviewWindow!, ordered: .above) diff --git a/LoveLiver-osx/MovieDocumentViewController.swift b/LoveLiver-osx/MovieDocumentViewController.swift index 5e29fe6..292625b 100644 --- a/LoveLiver-osx/MovieDocumentViewController.swift +++ b/LoveLiver-osx/MovieDocumentViewController.swift @@ -17,7 +17,7 @@ class MovieDocumentViewController: NSViewController { fileprivate let movieURL: URL fileprivate let player: AVPlayer fileprivate let playerItem: AVPlayerItem - var createLivePhotoAction: ((Void) -> Void)? + var createLivePhotoAction: (() -> Void)? fileprivate let playerView: AVPlayerView = AVPlayerView() ※ { v in v.controlsStyle = .floating diff --git a/LoveLiver-osx/MovieOverviewControl.swift b/LoveLiver-osx/MovieOverviewControl.swift index 2ce81e7..6f1a8ae 100644 --- a/LoveLiver-osx/MovieOverviewControl.swift +++ b/LoveLiver-osx/MovieOverviewControl.swift @@ -26,7 +26,7 @@ class MovieOverviewControl: NSView { tf.isBezeled = false tf.isEditable = false tf.drawsBackground = true - tf.font = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: NSFontWeightRegular) + tf.font = NSFont.monospacedDigitSystemFont(ofSize: 12, weight: .regular) tf.textColor = NSColor.white tf.backgroundColor = NSColor.black } @@ -75,7 +75,7 @@ class MovieOverviewControl: NSView { init(player: AVPlayer, playerItem: AVPlayerItem) { self.player = player - self.trimRange = CMTimeRange(start: kCMTimeZero, duration: playerItem.duration) + self.trimRange = CMTimeRange(start: .zero, duration: playerItem.duration) super.init(frame: NSZeroRect) @@ -85,8 +85,8 @@ class MovieOverviewControl: NSView { autolayout("H:|[currentTime]") autolayout("V:[currentTime]|") - setContentCompressionResistancePriority(NSLayoutPriorityDefaultHigh, for: .vertical) - setContentHuggingPriority(NSLayoutPriorityDefaultHigh, for: .vertical) + setContentCompressionResistancePriority(.defaultHigh, for: .vertical) + setContentHuggingPriority(.defaultHigh, for: .vertical) // subviews ordering addSubview(scopeMaskLeftView) @@ -218,7 +218,7 @@ class MovieOverviewControl: NSView { override func draw(_ dirtyRect: NSRect) { NSColor.black.setFill() - NSRectFillUsingOperation(dirtyRect, .copy) + dirtyRect.fill(using: .copy) var x: CGFloat = 0 for t in thumbnails { @@ -263,7 +263,7 @@ class MovieOverviewControl: NSView { fileprivate func seekToMousePosition(_ theEvent: NSEvent) { let p = convert(theEvent.locationInWindow, from: nil) let time = CMTimeAdd(CMTime(value: Int64(CGFloat(trimRange.duration.value) * p.x / bounds.width), timescale: trimRange.duration.timescale), trimRange.start) - player.seek(to: time, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero) + player.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero) } fileprivate func scopeToMousePosition(_ theEvent: NSEvent) { @@ -273,8 +273,8 @@ class MovieOverviewControl: NSView { let p = convert(theEvent.locationInWindow, from: nil) let distance = Int32(p.x - mouseDownLocation.x) - let start = CMTimeAdd(s.start, CMTimeMultiply(minFrameDuration, distance)) - let end = CMTimeAdd(s.end, CMTimeMultiply(minFrameDuration, distance)) + let start = CMTimeAdd(s.start, CMTimeMultiply(minFrameDuration, multiplier: distance)) + let end = CMTimeAdd(s.end, CMTimeMultiply(minFrameDuration, multiplier: distance)) let newScopeRange = CMTimeRange(start: start, end: end) if shouldUpdateScopeRange?(newScopeRange) == true { diff --git a/LoveLiver-osx/MovieOverviewViewController.swift b/LoveLiver-osx/MovieOverviewViewController.swift index b821e67..11dbd96 100644 --- a/LoveLiver-osx/MovieOverviewViewController.swift +++ b/LoveLiver-osx/MovieOverviewViewController.swift @@ -16,7 +16,7 @@ class MovieOverviewViewController: NSViewController { init(player: AVPlayer, playerItem: AVPlayerItem) { self.overview = MovieOverviewControl(player: player, playerItem: playerItem) - super.init(nibName: nil, bundle: nil)! + super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { @@ -34,7 +34,7 @@ class MovieOverviewViewController: NSViewController { } func movieDidLoad(_ videoSize: CGSize) { - overview.currentTime = kCMTimeZero + overview.currentTime = .zero overview.reload() } } diff --git a/LoveLiver-osx/OverviewTouchBarItemProvider.swift b/LoveLiver-osx/OverviewTouchBarItemProvider.swift index d0148b8..16493b5 100644 --- a/LoveLiver-osx/OverviewTouchBarItemProvider.swift +++ b/LoveLiver-osx/OverviewTouchBarItemProvider.swift @@ -20,19 +20,19 @@ protocol OverviewTouchBarItemProviderType : class { var dragging : Bool { get } @available(OSX 10.12.2, *) - func makeTouchbarItem(identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem + func makeTouchbarItem(identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem } @available(OSX 10.12.2, *) class OverviewTouchBarItemProvider : NSViewController, OverviewTouchBarItemProviderType { var shouldUpdateScopeRange: ((_ newValue: CMTimeRange?) -> Bool)? var onScopeChange: ((_ overview : MovieOverviewControl) -> Void)? - var trimRange : CMTimeRange = kCMTimeRangeZero { + var trimRange : CMTimeRange = .zero { didSet { overview.trimRange = trimRange } } - var scopeRange : CMTimeRange = kCMTimeRangeZero { + var scopeRange : CMTimeRange = .zero { didSet { overview.scopeRange = scopeRange } @@ -45,8 +45,8 @@ class OverviewTouchBarItemProvider : NSViewController, OverviewTouchBarItemProvi init(player: AVPlayer, playerItem: AVPlayerItem) { self.overview = MovieOverviewControl(player: player, playerItem: playerItem) self.overview.draggingMode = .scope - self.overview.imageGeneratorTolerance = kCMTimeZero - super.init(nibName: nil, bundle: nil)! + self.overview.imageGeneratorTolerance = .zero + super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { @@ -54,7 +54,7 @@ class OverviewTouchBarItemProvider : NSViewController, OverviewTouchBarItemProvi } - func makeTouchbarItem(identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem { + func makeTouchbarItem(identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem { return NSCustomTouchBarItem(identifier: identifier) ※ { item in item.viewController = self } @@ -96,7 +96,7 @@ class OverviewTouchBarItemProvider : NSViewController, OverviewTouchBarItemProvi private func seekToTouchPosition(_ touch: NSTouch) { let trimRange = overview.trimRange - let duration = overview.scopeRange?.duration ?? kCMTimeZero + let duration = overview.scopeRange?.duration ?? .zero let p = view.convert(touch.location(in: view), from: nil) diff --git a/LoveLiver.xcodeproj/project.pbxproj b/LoveLiver.xcodeproj/project.pbxproj index 5eacfe3..573be78 100644 --- a/LoveLiver.xcodeproj/project.pbxproj +++ b/LoveLiver.xcodeproj/project.pbxproj @@ -146,7 +146,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 1150; ORGANIZATIONNAME = mzp; TargetAttributes = { EA379AB51C68DE6D00106AEF = { @@ -160,6 +160,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -210,18 +211,20 @@ files = ( ); inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-LoveLiver-osx/Pods-LoveLiver-osx-frameworks.sh", + "${PODS_ROOT}/Target Support Files/Pods-LoveLiver-osx/Pods-LoveLiver-osx-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/FootlessParser/FootlessParser.framework", "${BUILT_PRODUCTS_DIR}/NorthLayout/NorthLayout.framework", "${BUILT_PRODUCTS_DIR}/※ikemen/Ikemen.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FootlessParser.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/NorthLayout.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Ikemen.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LoveLiver-osx/Pods-LoveLiver-osx-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-LoveLiver-osx/Pods-LoveLiver-osx-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -262,17 +265,28 @@ 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; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -305,17 +319,28 @@ 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; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 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_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; @@ -333,6 +358,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.11; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; }; name = Release; }; @@ -347,7 +373,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "jp.mzp.LoveLiver-osx"; PRODUCT_NAME = LoveLiver; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -362,7 +388,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "jp.mzp.LoveLiver-osx"; PRODUCT_NAME = LoveLiver; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/LoveLiver.xcodeproj/xcshareddata/xcschemes/LoveLiver-osx.xcscheme b/LoveLiver.xcodeproj/xcshareddata/xcschemes/LoveLiver-osx.xcscheme index fc3ed02..1c6c89d 100644 --- a/LoveLiver.xcodeproj/xcshareddata/xcschemes/LoveLiver-osx.xcscheme +++ b/LoveLiver.xcodeproj/xcshareddata/xcschemes/LoveLiver-osx.xcscheme @@ -1,6 +1,6 @@ - - - - + + - - String? { for item in metadata() { if item.key as? String == kKeyContentIdentifier && - item.keySpace == kKeySpaceQuickTimeMetadata { + item.keySpace == .quickTimeMetadata { return item.value as? String } } @@ -37,7 +37,7 @@ class QuickTimeMov { } func readStillImageTime() -> NSNumber? { - if let track = track(AVMediaTypeMetadata) { + if let track = track(.metadata) { let (reader, output) = try! self.reader(track, settings: nil) reader.startReading() @@ -47,7 +47,7 @@ class QuickTimeMov { let group = AVTimedMetadataGroup(sampleBuffer: buffer) for item in group?.items ?? [] { if item.key as? String == kKeyStillImageTime && - item.keySpace == kKeySpaceQuickTimeMetadata { + item.keySpace == .quickTimeMetadata { return item.numberValue } } @@ -62,7 +62,7 @@ class QuickTimeMov { // -------------------------------------------------- // reader for source video // -------------------------------------------------- - guard let track = self.track(AVMediaTypeVideo) else { + guard let track = self.track(.video) else { print("not found video track") return } @@ -73,11 +73,11 @@ class QuickTimeMov { // -------------------------------------------------- // writer for mov // -------------------------------------------------- - let writer = try AVAssetWriter(outputURL: URL(fileURLWithPath: dest), fileType: AVFileTypeQuickTimeMovie) + let writer = try AVAssetWriter(outputURL: URL(fileURLWithPath: dest), fileType: .mov) writer.metadata = [metadataFor(assetIdentifier)] // video track - let input = AVAssetWriterInput(mediaType: AVMediaTypeVideo, + let input = AVAssetWriterInput(mediaType: .video, outputSettings: videoSettings(track.naturalSize)) input.expectsMediaDataInRealTime = true input.transform = track.preferredTransform @@ -92,7 +92,7 @@ class QuickTimeMov { // -------------------------------------------------- writer.startWriting() reader.startReading() - writer.startSession(atSourceTime: kCMTimeZero) + writer.startSession(atSourceTime: .zero) // write metadata track adapter.append(AVTimedMetadataGroup(items: [metadataForStillImageTime()], @@ -104,7 +104,7 @@ class QuickTimeMov { if reader.status == .reading { if let buffer = output.copyNextSampleBuffer() { if !input.append(buffer) { - print("cannot write: \(writer.error)") + print("cannot write: \(String(describing: writer.error))") reader.cancelReading() } } @@ -132,10 +132,10 @@ class QuickTimeMov { } fileprivate func metadata() -> [AVMetadataItem] { - return asset.metadata(forFormat: AVMetadataFormatQuickTimeMetadata) + return asset.metadata(forFormat: .quickTimeMetadata) } - fileprivate func track(_ mediaType : String) -> AVAssetTrack? { + fileprivate func track(_ mediaType: AVMediaType) -> AVAssetTrack? { return asset.tracks(withMediaType: mediaType).first } @@ -154,8 +154,8 @@ class QuickTimeMov { "com.apple.metadata.datatype.int8" ] var desc : CMFormatDescription? = nil - CMMetadataFormatDescriptionCreateWithMetadataSpecifications(kCFAllocatorDefault, kCMMetadataFormatType_Boxed, [spec] as CFArray, &desc) - let input = AVAssetWriterInput(mediaType: AVMediaTypeMetadata, + CMMetadataFormatDescriptionCreateWithMetadataSpecifications(allocator: kCFAllocatorDefault, metadataType: kCMMetadataFormatType_Boxed, metadataSpecifications: [spec] as CFArray, formatDescriptionOut: &desc) + let input = AVAssetWriterInput(mediaType: .metadata, outputSettings: nil, sourceFormatHint: desc) return AVAssetWriterInputMetadataAdaptor(assetWriterInput: input) } @@ -171,7 +171,7 @@ class QuickTimeMov { fileprivate func metadataFor(_ assetIdentifier: String) -> AVMetadataItem { let item = AVMutableMetadataItem() item.key = kKeyContentIdentifier as (NSCopying & NSObjectProtocol)? - item.keySpace = kKeySpaceQuickTimeMetadata + item.keySpace = .quickTimeMetadata item.value = assetIdentifier as (NSCopying & NSObjectProtocol)? item.dataType = "com.apple.metadata.datatype.UTF-8" return item @@ -180,7 +180,7 @@ class QuickTimeMov { fileprivate func metadataForStillImageTime() -> AVMetadataItem { let item = AVMutableMetadataItem() item.key = kKeyStillImageTime as (NSCopying & NSObjectProtocol)? - item.keySpace = kKeySpaceQuickTimeMetadata + item.keySpace = .quickTimeMetadata item.value = 0 as (NSCopying & NSObjectProtocol)? item.dataType = "com.apple.metadata.datatype.int8" return item diff --git a/Podfile.lock b/Podfile.lock index 112d719..95a1ef3 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,20 +1,24 @@ PODS: - - NorthLayout (3.0.0) - - "※ikemen (0.2.0)" + - FootlessParser (0.5.2) + - NorthLayout (5.2.0): + - FootlessParser (~> 0.4) + - "※ikemen (0.6.0)" DEPENDENCIES: - NorthLayout - "※ikemen" SPEC REPOS: - https://github.com/CocoaPods/Specs.git: + trunk: + - FootlessParser - NorthLayout - "※ikemen" SPEC CHECKSUMS: - NorthLayout: 28db8bfa49b861b4e972cc8e7c683c8ba819ff88 - "※ikemen": c04aecee4293a2b6deb2119f7e67e7a82c6dea06 + FootlessParser: 521916d592fa6cba06cfca6f4b5d4f5a2d49175a + NorthLayout: 308a58a8f7d96f316e6399ff6432f8769321bbdf + "※ikemen": da47fe6e0acfbe241611221f4d98ade266bf50a2 PODFILE CHECKSUM: 8f7e2e0c449e19a45b4f4bb0d60e9a078496f69f -COCOAPODS: 1.5.0 +COCOAPODS: 1.9.3 From 792eceda3180f4abd6831943c7c14db95a0a154c Mon Sep 17 00:00:00 2001 From: banjun Date: Mon, 12 Oct 2020 01:46:13 +0900 Subject: [PATCH 2/2] use Any over AnyObject as outdated in the frameworks --- LoveLiver-osx/AppDelegate.swift | 2 +- LoveLiver-osx/MovieOverviewControl.swift | 4 ++-- LoveLiver/QuickTimeMov.swift | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/LoveLiver-osx/AppDelegate.swift b/LoveLiver-osx/AppDelegate.swift index 86322e5..ed17d1a 100644 --- a/LoveLiver-osx/AppDelegate.swift +++ b/LoveLiver-osx/AppDelegate.swift @@ -20,7 +20,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { return true } - @objc private func openDocument(_ sender: AnyObject?) { + @objc private func openDocument(_ sender: Any?) { NSDocumentController.shared.openDocument(sender) } } diff --git a/LoveLiver-osx/MovieOverviewControl.swift b/LoveLiver-osx/MovieOverviewControl.swift index 6f1a8ae..0a44577 100644 --- a/LoveLiver-osx/MovieOverviewControl.swift +++ b/LoveLiver-osx/MovieOverviewControl.swift @@ -13,7 +13,7 @@ import NorthLayout class MovieOverviewControl: NSView { let player: AVPlayer - var playerTimeObserver: AnyObject? + var playerTimeObserver: Any? var currentTime: CMTime? { didSet { updateCurrentTime() } } @@ -159,7 +159,7 @@ class MovieOverviewControl: NSView { playerTimeObserver = player.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 30), queue: DispatchQueue.main) { [weak self] time in self?.currentTime = time - } as AnyObject? + } } override func viewDidEndLiveResize() { diff --git a/LoveLiver/QuickTimeMov.swift b/LoveLiver/QuickTimeMov.swift index 00b8fd7..242844a 100644 --- a/LoveLiver/QuickTimeMov.swift +++ b/LoveLiver/QuickTimeMov.swift @@ -139,7 +139,7 @@ class QuickTimeMov { return asset.tracks(withMediaType: mediaType).first } - fileprivate func reader(_ track : AVAssetTrack, settings: [String:AnyObject]?) throws -> (AVAssetReader, AVAssetReaderOutput) { + fileprivate func reader(_ track : AVAssetTrack, settings: [String: Any]?) throws -> (AVAssetReader, AVAssetReaderOutput) { let output = AVAssetReaderTrackOutput(track: track, outputSettings: settings) let reader = try AVAssetReader(asset: asset) reader.add(output) @@ -160,11 +160,11 @@ class QuickTimeMov { return AVAssetWriterInputMetadataAdaptor(assetWriterInput: input) } - fileprivate func videoSettings(_ size : CGSize) -> [String:AnyObject] { + fileprivate func videoSettings(_ size : CGSize) -> [String: Any] { return [ - AVVideoCodecKey: AVVideoCodecH264 as AnyObject, - AVVideoWidthKey: size.width as AnyObject, - AVVideoHeightKey: size.height as AnyObject + AVVideoCodecKey: AVVideoCodecH264, + AVVideoWidthKey: size.width, + AVVideoHeightKey: size.height ] }