Skip to content

Commit

Permalink
Merge pull request #2 from marmelroy/swift3.0
Browse files Browse the repository at this point in the history
Swift3.0
  • Loading branch information
gwjakewelton authored Aug 17, 2016
2 parents 167daea + 376f3ef commit db76c1b
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 228 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# MacOS
.DS_Store
# Xcode
#
build/
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
osx_image: xcode7.2
osx_image: xcode8
language: objective-c
env:
global:
- LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8
before_install:
- brew update || brew update
- brew outdated xctool || brew upgrade xctool
- gem install cocoapods
- xcrun simctl list
install: echo "<3"
env:
- MODE=framework
Expand All @@ -19,3 +17,4 @@ script: ./build.sh $MODE
branches:
only:
- master
- swift3.0
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ catch {

## Advanced Zip

For more advanced usage, Zip has functions that let you set custom destination paths, work with password protected zips and use a progress handling closure. These function throw if there is an error but don't return.
For more advanced usage, Zip has functions that let you set custom destination paths, work with password protected zips and use a progress handling closure. These functions throw if there is an error but don't return.
```swift
do {
let filePath = NSBundle.mainBundle().URLForResource("file", withExtension: "zip")!
Expand All @@ -51,6 +51,13 @@ catch {
}
```

## Custom File Extensions

Zip supports '.zip' and '.cbz' files out of the box. To support additional zip-derivative file extensions:
```
Zip.addCustomFileExtension("file-extension-here")
```


### Setting up with Carthage

Expand Down
4 changes: 2 additions & 2 deletions Zip copy-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.4.1</string>
<string>0.4.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>6</string>
<string>7</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion Zip.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "Zip"
s.version = "0.4.1"
s.version = "0.4.3"
s.summary = "Zip and unzip files in Swift."

# This description is used to generate tags and improve search results.
Expand Down
32 changes: 21 additions & 11 deletions Zip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Roy Marmelstein";
TargetAttributes = {
343F50FE1C8DAEEC0028C434 = {
Expand All @@ -504,9 +504,11 @@
};
347E3A731C1DFFB500A11FD3 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
347E3A7D1C1DFFB500A11FD3 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -677,7 +679,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 6;
DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Zip copy-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -702,7 +704,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 6;
DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Zip copy-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -714,6 +716,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvsimulator appletvos";
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -724,10 +727,10 @@
buildSettings = {
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 6;
DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = Zip/Info.plist;
Expand All @@ -747,10 +750,10 @@
buildSettings = {
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 6;
DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = Zip/Info.plist;
Expand All @@ -762,6 +765,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand Down Expand Up @@ -812,7 +816,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -860,7 +864,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 6;
CURRENT_PROJECT_VERSION = 7;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -889,7 +893,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 6;
DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Zip/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -901,6 +905,7 @@
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -911,7 +916,7 @@
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 6;
DYLIB_CURRENT_VERSION = 7;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Zip/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -922,6 +927,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/Zip/minizip/**";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -932,6 +939,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.ZipTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -942,6 +950,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.ZipTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "F3707899-72AE-49DA-9BDD-5CB0B64CF03A",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"8DA5B175D3FDB92A3B3CCBD4109A734F1316A3DD" : "Zip\/Zip\/minizip\/",
"3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip\/"
"3DD768C8AB2D6A2647C9EF99992D3CC5820E77C4" : "Zip-swift3\/"
},
"DVTSourceControlWorkspaceBlueprintNameKey" : "Zip",
"DVTSourceControlWorkspaceBlueprintVersion" : 204,
Expand Down
2 changes: 1 addition & 1 deletion Zip.xcodeproj/xcshareddata/xcschemes/Zip OSX.xcscheme
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
2 changes: 1 addition & 1 deletion Zip.xcodeproj/xcshareddata/xcschemes/Zip tvOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Zip.xcodeproj/xcshareddata/xcschemes/Zip.xcscheme
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
2 changes: 1 addition & 1 deletion Zip.xcodeproj/xcshareddata/xcschemes/ZipTests.xcscheme
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
4 changes: 2 additions & 2 deletions Zip/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.4.1</string>
<string>0.4.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>6</string>
<string>7</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
37 changes: 21 additions & 16 deletions Zip/QuickZip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
public class func quickUnzipFile(path: NSURL) throws -> NSURL {
public class func quickUnzipFile(_ path: URL) throws -> URL {
return try quickUnzipFile(path, progress: nil)
}

Expand All @@ -37,16 +37,21 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
public class func quickUnzipFile(path: NSURL, progress: ((progress: Double) -> ())?) throws -> NSURL {
let fileManager = NSFileManager.defaultManager()
guard let fileExtension = path.pathExtension, let fileName = path.lastPathComponent else {
throw ZipError.UnzipFail
public class func quickUnzipFile(_ path: URL, progress: ((progress: Double) -> ())?) throws -> URL {
let fileManager = FileManager.default

let fileExtension = path.pathExtension
let fileName = path.lastPathComponent

let directoryName = fileName.replacingOccurrences(of: ".\(fileExtension)", with: "")
let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
do {
let destinationUrl = documentsUrl.appendingPathComponent(directoryName, isDirectory: true)
try self.unzipFile(path, destination: destinationUrl, overwrite: true, password: nil, progress: progress)
return destinationUrl
}catch{
throw(ZipError.unzipFail)
}
let directoryName = fileName.stringByReplacingOccurrencesOfString(".\(fileExtension)", withString: "")
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
let destinationUrl = documentsUrl.URLByAppendingPathComponent(directoryName, isDirectory: true)
try self.unzipFile(path, destination: destinationUrl, overwrite: true, password: nil, progress: progress)
return destinationUrl
}

//MARK: Quick Zip
Expand All @@ -63,7 +68,7 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
public class func quickZipFiles(paths: [NSURL], fileName: String) throws -> NSURL {
public class func quickZipFiles(_ paths: [URL], fileName: String) throws -> URL {
return try quickZipFiles(paths, fileName: fileName, progress: nil)
}

Expand All @@ -80,13 +85,13 @@ extension Zip {
- returns: NSURL of the destination folder.
*/
public class func quickZipFiles(paths: [NSURL], fileName: String, progress: ((progress: Double) -> ())?) throws -> NSURL {
let fileManager = NSFileManager.defaultManager()
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
let destinationUrl = documentsUrl.URLByAppendingPathComponent("\(fileName).zip")
public class func quickZipFiles(_ paths: [URL], fileName: String, progress: ((progress: Double) -> ())?) throws -> URL {
let fileManager = FileManager.default
let documentsUrl = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0] as URL
let destinationUrl = try! documentsUrl.appendingPathComponent("\(fileName).zip")
try self.zipFiles(paths, zipFilePath: destinationUrl, password: nil, progress: progress)
return destinationUrl
}


}
}
Loading

0 comments on commit db76c1b

Please sign in to comment.