Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Support Swift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Wang committed Sep 18, 2016
1 parent e0d6be6 commit 419de22
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 219 deletions.
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Alamofire/Alamofire" ~> 3.0
github "teambition/Alamofire" "ios8-support"
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Alamofire/Alamofire" "3.4.2"
github "teambition/Alamofire" "b64b7e0df813ea63686f9228db676509cf84a4df"
16 changes: 9 additions & 7 deletions Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
4A6BC7931C76F8C500DACDA5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4A6BC7921C76F8C500DACDA5 /* Assets.xcassets */; };
4A6BC7961C76F8C500DACDA5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A6BC7941C76F8C500DACDA5 /* LaunchScreen.storyboard */; };
4A725BBA1C7D947800244964 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A725BB91C7D947800244964 /* Alamofire.framework */; };
AC4B400D1D8D173C004A189D /* FilePreviewController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AC4B400C1D8D173C004A189D /* FilePreviewController.framework */; };
AC4B400E1D8D173C004A189D /* FilePreviewController.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = AC4B400C1D8D173C004A189D /* FilePreviewController.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -24,7 +22,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
AC4B400E1D8D173C004A189D /* FilePreviewController.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -40,7 +37,6 @@
4A6BC7951C76F8C500DACDA5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
4A6BC7971C76F8C500DACDA5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4A725BB91C7D947800244964 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = Carthage/Build/iOS/Alamofire.framework; sourceTree = "<group>"; };
AC4B400C1D8D173C004A189D /* FilePreviewController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = FilePreviewController.framework; path = "/Users/zhangxiaolian/Library/Developer/Xcode/DerivedData/FilePreviewController-bsrhegqbraqcqagslateiirtfgpb/Build/Products/Debug-iphonesimulator/FilePreviewController.framework"; sourceTree = "<absolute>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -49,7 +45,6 @@
buildActionMask = 2147483647;
files = (
4A725BBA1C7D947800244964 /* Alamofire.framework in Frameworks */,
AC4B400D1D8D173C004A189D /* FilePreviewController.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -59,7 +54,6 @@
4A6BC77F1C76F8C500DACDA5 = {
isa = PBXGroup;
children = (
AC4B400C1D8D173C004A189D /* FilePreviewController.framework */,
4A725BB91C7D947800244964 /* Alamofire.framework */,
4A6BC78A1C76F8C500DACDA5 /* Demo */,
4A6BC7891C76F8C500DACDA5 /* Products */,
Expand Down Expand Up @@ -116,11 +110,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Teambition;
TargetAttributes = {
4A6BC7871C76F8C500DACDA5 = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -217,8 +212,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";
Expand Down Expand Up @@ -262,8 +259,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";
Expand All @@ -282,6 +281,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;
};
Expand All @@ -300,6 +300,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.Teambition.Demo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -316,6 +317,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.Teambition.Demo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
12 changes: 6 additions & 6 deletions Demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: 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:.
}

Expand Down
24 changes: 12 additions & 12 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ class ViewController: UIViewController, QLPreviewControllerDataSource, FilePrevi
// Dispose of any resources that can be recreated.
}

@IBAction func buttonTap(sender: UIButton) {
let item1 = FPActionBarItem(title: "ONE", style: .Plain) { (controller, _) in
@IBAction func buttonTap(_ sender: UIButton) {
let item1 = FPActionBarItem(title: "ONE", style: .plain) { (controller, _) in
let viewController = UIViewController()
viewController.title = "After FilePreviewController"
viewController.view.backgroundColor = UIColor.whiteColor()
viewController.view.backgroundColor = UIColor.white
controller.navigationController?.pushViewController(viewController, animated: true)
}
item1.barButtonItem.tintColor = UIColor.blackColor()
item1.barButtonItem.tintColor = UIColor.black

let item2 = FPActionBarItem(title: "TWO", style: .Plain) { (controller, item) in
let item2 = FPActionBarItem(title: "TWO", style: .plain) { (controller, item) in
controller.beginUpdate()
controller.update(progress: 0.5)
print(item)
}
item2.barButtonItem.tintColor = UIColor.blackColor()
item2.barButtonItem.tintColor = UIColor.black

// let url = NSURL(string: jpg)
// let item = FilePreviewItem(previewItemURL: url!, previewItemTitle: "Good Good File/Good File.jpg", fileExtension: "jpg")

let mp3 = NSURL(string: "https://striker.teambition.net/storage/100kf674d16270578354550f650a5c245ece?download=Agile-Scrum-Lean%20Startup%E5%BD%95%E9%9F%B3-%E5%A7%9C%E7%BF%94-20160908.mp3&Signature=eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6Ii9zdG9yYWdlLzEwMGtmNjc0ZDE2MjcwNTc4MzU0NTUwZjY1MGE1YzI0NWVjZSIsImV4cCI6MTQ3NDI0MzIwMH0.15JpJhYPh5w332TmLgGYrQzfT0jsDdRCTlHyz6frfsY")
let mp3 = URL(string: "https://striker.teambition.net/storage/100kf674d16270578354550f650a5c245ece?download=Agile-Scrum-Lean%20Startup%E5%BD%95%E9%9F%B3-%E5%A7%9C%E7%BF%94-20160908.mp3&Signature=eyJhbGciOiJIUzI1NiJ9.eyJyZXNvdXJjZSI6Ii9zdG9yYWdlLzEwMGtmNjc0ZDE2MjcwNTc4MzU0NTUwZjY1MGE1YzI0NWVjZSIsImV4cCI6MTQ3NDI0MzIwMH0.15JpJhYPh5w332TmLgGYrQzfT0jsDdRCTlHyz6frfsY")
let item = FilePreviewItem(previewItemURL: mp3!, previewItemTitle: "123.mp3", fileExtension: "mpge")
// Show SingleFilePreviewController, you can also push it into navigation controller
let singleFilePreviewController = SingleFilePreviewController(previewItem: item)
Expand All @@ -68,20 +68,20 @@ class ViewController: UIViewController, QLPreviewControllerDataSource, FilePrevi
}

// MARK: Demo for FilePreviewController
func numberOfPreviewItemsInPreviewController(controller: QLPreviewController) -> Int {
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1
}

func previewController(controller: QLPreviewController, previewItemAtIndex index: Int) -> QLPreviewItem {
let url = NSURL(string: jpg)
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
let url = URL(string: jpg)
let item = FilePreviewItem(previewItemURL: url!, previewItemTitle: "Good File", fileExtension: "csv")
return item
}

func previewController(controller: FilePreviewController, failedToLoadRemotePreviewItem item: FilePreviewItem, error: NSError) {
func previewController(_ controller: FilePreviewController, failedToLoadRemotePreviewItem item: FilePreviewItem, error: NSError) {
}

func previewController(controller: FilePreviewController, willShareItem item: FilePreviewItem) {
func previewController(_ controller: FilePreviewController, willShareItem item: FilePreviewItem) {
print("Custom Share Action")
}

Expand Down
14 changes: 13 additions & 1 deletion FilePreviewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@
4A6BC76B1C76F89300DACDA5 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Teambition;
TargetAttributes = {
4A6BC7731C76F89300DACDA5 = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -194,8 +195,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";
Expand Down Expand Up @@ -243,8 +246,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";
Expand All @@ -264,6 +269,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -275,6 +281,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -285,12 +292,14 @@
);
INFOPLIST_FILE = FilePreviewController/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.Teambition.FilePreviewController;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -299,6 +308,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -309,10 +319,12 @@
);
INFOPLIST_FILE = FilePreviewController/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.Teambition.FilePreviewController;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
16 changes: 8 additions & 8 deletions FilePreviewController/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@

import Foundation

public struct Error {
public struct FPError {

public static let Domain = "com.filepreviewcontroller.error"
public static let RelatedErrorKey = "com.filepreviewcontroller.error.relatederror"

public enum Code: Int {
case LocalCacheDirectoryCreateFailed = -7001
case RemoteFileDownloadFailed = -7002
case localCacheDirectoryCreateFailed = -7001
case remoteFileDownloadFailed = -7002
}

public static func errorWithCode(code: Code, failureReason: String, error: NSError? = nil) -> NSError {
public static func errorWithCode(_ code: Code, failureReason: String, error: Error? = nil) -> NSError {
return errorWithCode(code.rawValue, failureReason: failureReason, error: nil)
}

public static func errorWithCode(code: Int, failureReason: String, error: NSError?) -> NSError {
var userInfo: [String: AnyObject] = [NSLocalizedDescriptionKey: failureReason]
public static func errorWithCode(_ code: Int, failureReason: String, error: Error?) -> NSError {
var userInfo: [String: AnyObject] = [NSLocalizedDescriptionKey: failureReason as AnyObject]
if let error = error {
userInfo[RelatedErrorKey] = error
userInfo[RelatedErrorKey] = error as AnyObject?
}
return NSError(domain: Domain, code: code, userInfo: userInfo)
}
}
}
20 changes: 10 additions & 10 deletions FilePreviewController/FPActionBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import Foundation

public typealias BarActionClosure = (FilePreviewController, FPActionBarItem) -> Void

public class FPActionBarItem: NSObject {
public var barButtonItem: UIBarButtonItem!
public var action: BarActionClosure?
public weak var filePreviewController: FilePreviewController?
open class FPActionBarItem: NSObject {
open var barButtonItem: UIBarButtonItem!
open var action: BarActionClosure?
open weak var filePreviewController: FilePreviewController?

public init(title: String?, style: UIBarButtonItemStyle, action: BarActionClosure? = nil) {
super.init()
self.action = action
barButtonItem = UIBarButtonItem(title: title, style: .Plain, target: self, action: #selector(FPActionBarItem.triggerAction))
barButtonItem = UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(FPActionBarItem.triggerAction))
}

public init(image: UIImage?, style: UIBarButtonItemStyle, action: BarActionClosure? = nil) {
Expand All @@ -36,27 +36,27 @@ public class FPActionBarItem: NSObject {
}

func triggerAction() {
guard let filePreviewController = filePreviewController, action = action else {
guard let filePreviewController = filePreviewController, let action = action else {
return
}
action(filePreviewController, self)
}
}

public extension FilePreviewController {
func addActionBarItem(title title: String?, style: UIBarButtonItemStyle, action: BarActionClosure?) {
func addActionBarItem(title: String?, style: UIBarButtonItemStyle, action: BarActionClosure?) {
let barItem = FPActionBarItem(title: title, style: style, action: action)
barItem.filePreviewController = self
actionItems.append(barItem)
}

func insert(actionBarItem: FPActionBarItem, at index: Int) {
func insert(_ actionBarItem: FPActionBarItem, at index: Int) {
let barItem = actionBarItem
barItem.filePreviewController = self
actionItems.insert(barItem, atIndex: index)
actionItems.insert(barItem, at: index)
}

func removeAllToolbarItems() {
actionItems.removeAll()
}
}
}
Loading

0 comments on commit 419de22

Please sign in to comment.