From a7a8cdf26192fbdf69c78ab9b286d09d1f8f3771 Mon Sep 17 00:00:00 2001 From: Gui Sabran Date: Thu, 9 Jul 2020 13:16:36 -0700 Subject: [PATCH] add swift package, and remove OBJC code in Swift files --- Mixpanel/ExceptionWrapper.h | 15 --------------- Mixpanel/ExceptionWrapper.m | 25 ------------------------- Mixpanel/Mixpanel.h | 18 ------------------ Mixpanel/Persistence.swift | 24 +++++++----------------- Package.swift | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 75 deletions(-) delete mode 100644 Mixpanel/ExceptionWrapper.h delete mode 100644 Mixpanel/ExceptionWrapper.m delete mode 100644 Mixpanel/Mixpanel.h create mode 100644 Package.swift diff --git a/Mixpanel/ExceptionWrapper.h b/Mixpanel/ExceptionWrapper.h deleted file mode 100644 index 19e597646..000000000 --- a/Mixpanel/ExceptionWrapper.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ExceptionWrapper.h -// Mixpanel -// -// Created by Zihe Jia on 8/29/18. -// Copyright © 2018 Mixpanel. All rights reserved. -// - -#import - -@interface ExceptionWrapper : NSObject - -+ (void)try:(void(^)(void))try catch:(void(^)(NSException *exception))catch finally:(void(^)(void))finally; - -@end diff --git a/Mixpanel/ExceptionWrapper.m b/Mixpanel/ExceptionWrapper.m deleted file mode 100644 index 9b56cc32e..000000000 --- a/Mixpanel/ExceptionWrapper.m +++ /dev/null @@ -1,25 +0,0 @@ -// -// ExceptionWrapper.m -// Mixpanel -// -// Created by Zihe Jia on 8/29/18. -// Copyright © 2018 Mixpanel. All rights reserved. -// - -#import "ExceptionWrapper.h" - -@implementation ExceptionWrapper - -+ (void)try:(void(^)(void))try catch:(void(^)(NSException *exception))catch finally:(void(^)(void))finally { - @try { - try ? try() : nil; - } - @catch (NSException *exception) { - catch ? catch(exception) : nil; - } - @finally { - finally ? finally() : nil; - } -} - -@end diff --git a/Mixpanel/Mixpanel.h b/Mixpanel/Mixpanel.h deleted file mode 100644 index 4f53bbbbb..000000000 --- a/Mixpanel/Mixpanel.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// Mixpanel.h -// Mixpanel -// -// Created by Yarden Eitan on 6/1/16. -// Copyright © 2016 Mixpanel. All rights reserved. -// - -@import Foundation; -#import "ExceptionWrapper.h" - -//! Project version number for Mixpanel. -FOUNDATION_EXPORT double MixpanelVersionNumber; - -//! Project version string for Mixpanel. -FOUNDATION_EXPORT const unsigned char MixpanelVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import diff --git a/Mixpanel/Persistence.swift b/Mixpanel/Persistence.swift index 7e8d4d3fa..7202456bb 100644 --- a/Mixpanel/Persistence.swift +++ b/Mixpanel/Persistence.swift @@ -159,15 +159,10 @@ class Persistence { return } - ExceptionWrapper.try({ [cObject = archiveObject, cPath = path, cType = type] in - if !NSKeyedArchiver.archiveRootObject(cObject, toFile: cPath) { - Logger.error(message: "failed to archive \(cType.rawValue)") - return - } - }, catch: { [cType = type] (error) in - Logger.error(message: "failed to archive \(cType.rawValue) due to an uncaught exception") + if !NSKeyedArchiver.archiveRootObject(archiveObject, toFile: path) { + Logger.error(message: "failed to archive \(type.rawValue)") return - }, finally: {}) + } addSkipBackupAttributeToItem(at: path) } @@ -283,16 +278,11 @@ class Persistence { static private func unarchiveWithFilePath(_ filePath: String) -> Any? { var unarchivedData: Any? = nil - ExceptionWrapper.try({ [filePath] in - unarchivedData = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) - if unarchivedData == nil { - Logger.info(message: "Unable to read file at path: \(filePath)") - removeArchivedFile(atPath: filePath) - } - }, catch: { [filePath] (error) in + unarchivedData = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) + if unarchivedData == nil { + Logger.info(message: "Unable to read file at path: \(filePath)") removeArchivedFile(atPath: filePath) - Logger.info(message: "Unable to read file at path: \(filePath), error: \(String(describing: error))") - }, finally: {}) + } return unarchivedData } diff --git a/Package.swift b/Package.swift new file mode 100644 index 000000000..036d1bd33 --- /dev/null +++ b/Package.swift @@ -0,0 +1,32 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "Mixpanel", + platforms: [ + .iOS(.v8), + .tvOS(.v9), + .macOS(.v10_10), + .watchOS(.v3), + ], + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "Mixpanel", + targets: ["Mixpanel"]) + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "Mixpanel", + dependencies: [], + path: "Mixpanel"), + ] +)