Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Update to Swift 5.0 #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Examples/MonoImage/MonoImage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "eje Inc.";
TargetAttributes = {
BFB8923F1E2F9CFF00FA9129 = {
Expand All @@ -157,7 +157,7 @@
};
buildConfigurationList = BFB8923B1E2F9CFF00FA9129 /* Build configuration list for PBXProject "MonoImage" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -242,6 +242,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand All @@ -251,13 +252,15 @@
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_DOCUMENTATION_COMMENTS = YES;
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;
Expand Down Expand Up @@ -296,6 +299,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand All @@ -305,13 +309,15 @@
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_DOCUMENTATION_COMMENTS = YES;
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;
Expand Down Expand Up @@ -350,7 +356,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope.MonoImage";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -366,7 +372,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope.MonoImage";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions Examples/MonoImage/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import UIKit
@UIApplicationMain
final 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]? = nil) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
Expand Down
6 changes: 5 additions & 1 deletion Examples/MonoImage/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class ViewController: UIViewController {
NSLayoutConstraint.activate(constraints)

// double tap to reset rotation
let doubleTapGestureRecognizer = UITapGestureRecognizer(target: panoramaView, action: #selector(PanoramaView.setNeedsResetRotation(_:)))
let doubleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(resetRotation))
doubleTapGestureRecognizer.numberOfTapsRequired = 2
panoramaView.addGestureRecognizer(doubleTapGestureRecognizer)

Expand All @@ -64,4 +64,8 @@ final class ViewController: UIViewController {

panoramaView?.updateInterfaceOrientation(with: coordinator)
}

@objc func resetRotation() {
panoramaView?.setNeedsResetRotation()
}
}
14 changes: 10 additions & 4 deletions Examples/MonoVideo/MonoVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "eje Inc.";
TargetAttributes = {
BFA89A981E3117C0005A3529 = {
Expand All @@ -160,7 +160,7 @@
};
buildConfigurationList = BFA89A941E3117C0005A3529 /* Build configuration list for PBXProject "MonoVideo" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -246,6 +246,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand All @@ -255,13 +256,15 @@
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_DOCUMENTATION_COMMENTS = YES;
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;
Expand Down Expand Up @@ -300,6 +303,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand All @@ -309,13 +313,15 @@
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_DOCUMENTATION_COMMENTS = YES;
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;
Expand Down Expand Up @@ -354,7 +360,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope.MonoVideo";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -370,7 +376,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.eje-c.MetalScope.MonoVideo";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions Examples/MonoVideo/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import UIKit
@UIApplicationMain
final 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]? = nil) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
"idiom" : "ipad",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
86 changes: 80 additions & 6 deletions Examples/MonoVideo/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import MetalScope
import AVFoundation

final class ViewController: UIViewController {

typealias SeekOperationBlock = () -> Void

fileprivate var timeObserverToken: Any?
fileprivate var isSeeking: Bool = false

lazy var device: MTLDevice = {
guard let device = MTLCreateSystemDefaultDevice() else {
fatalError("Failed to create MTLDevice")
Expand All @@ -20,7 +26,8 @@ final class ViewController: UIViewController {
}()

weak var panoramaView: PanoramaView?

fileprivate var slider: UISlider!

var player: AVPlayer?
var playerLooper: Any? // AVPlayerLooper if available
var playerObservingToken: Any?
Expand All @@ -29,32 +36,48 @@ final class ViewController: UIViewController {
if let token = playerObservingToken {
NotificationCenter.default.removeObserver(token)
}

removePeriodicTimeObserver()
}

private func loadPanoramaView() {
let panoramaView = PanoramaView(frame: view.bounds, device: device)
panoramaView.setNeedsResetRotation()
panoramaView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(panoramaView)

slider = UISlider(frame: CGRect(x: 30, y: view.bounds.height - 60, width: view.bounds.width - 60, height: 30))
slider.minimumValue = 0
slider.maximumValue = 1
slider.isContinuous = true
slider.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(slider)

// fill parent view
let constraints: [NSLayoutConstraint] = [
panoramaView.topAnchor.constraint(equalTo: view.topAnchor),
panoramaView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
panoramaView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
panoramaView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
panoramaView.trailingAnchor.constraint(equalTo: view.trailingAnchor),

slider.heightAnchor.constraint(equalToConstant: 30.0),
slider.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -40),
slider.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30),
slider.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30)
]
NSLayoutConstraint.activate(constraints)

// double tap to reset rotation
let doubleTapGestureRecognizer = UITapGestureRecognizer(target: panoramaView, action: #selector(PanoramaView.setNeedsResetRotation(_:)))
let doubleTapGestureRecognizer = UITapGestureRecognizer(target: self, action:#selector(resetRotation))
doubleTapGestureRecognizer.numberOfTapsRequired = 2
panoramaView.addGestureRecognizer(doubleTapGestureRecognizer)

// single tap to toggle play/pause
let singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(togglePlaying))
singleTapGestureRecognizer.require(toFail: doubleTapGestureRecognizer)
panoramaView.addGestureRecognizer(singleTapGestureRecognizer)

slider.addTarget(self, action: #selector(seekVideo), for: .valueChanged)

self.panoramaView = panoramaView
}
Expand All @@ -74,10 +97,11 @@ final class ViewController: UIViewController {
} else {
player.actionAtItemEnd = .none
playerObservingToken = NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: playerItem, queue: nil) { _ in
player.seek(to: kCMTimeZero, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero)
player.seek(to: CMTime.zero, toleranceBefore: CMTime.zero, toleranceAfter: CMTime.zero)
}
}


addPeriodicTimeObserver()
player.play()
}

Expand All @@ -98,7 +122,7 @@ final class ViewController: UIViewController {
return .lightContent
}

func togglePlaying() {
@objc func togglePlaying() {
guard let player = player else {
return
}
Expand All @@ -109,4 +133,54 @@ final class ViewController: UIViewController {
player.pause()
}
}

@objc func resetRotation() {
panoramaView?.setNeedsResetRotation()
}

@objc func seekVideo(_ slider: UISlider) {
guard !isSeeking else { return }
guard let videoDuration = self.player?.currentItem?.duration else {
return
}
isSeeking = true
removePeriodicTimeObserver()
let tolerance = CMTime.zero
let time = CMTime(seconds: videoDuration.seconds * Double(slider.value), preferredTimescale: videoDuration.timescale)
player?.seek(to: time, toleranceBefore: tolerance, toleranceAfter: tolerance, completionHandler: { [weak self] (finished) in
self?.addPeriodicTimeObserver()
self?.isSeeking = false
print("seek result: \(finished)")
})
}
}

fileprivate extension ViewController {

func addPeriodicTimeObserver() {
// Invoke callback every half second
let interval = CMTime(seconds: 0.5, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
// Queue on which to invoke the callback
let mainQueue = DispatchQueue.main
// Add time observer
timeObserverToken = player?.addPeriodicTimeObserver(forInterval: interval, queue: mainQueue) { [weak self] time in
self?.updateSlider()
}
}

func removePeriodicTimeObserver() {
if let token = timeObserverToken {
player?.removeTimeObserver(token)
timeObserverToken = nil
}
}

func updateSlider() {
guard let videoDuration = self.player?.currentItem?.duration.seconds else {
return
}

let currentPlayOffset = self.player!.currentTime().seconds
slider.value = Float(currentPlayOffset / videoDuration)
}
}
4 changes: 2 additions & 2 deletions Examples/StereoImage/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import UIKit
@UIApplicationMain
final 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]? = nil) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.tintColor = .white
window?.rootViewController = ViewController()
Expand Down
Loading