Commit c31fd888 authored by Roy Marmelstein's avatar Roy Marmelstein

Creating File Browser for Sample app

parent 9f0f826f
...@@ -8,14 +8,13 @@ ...@@ -8,14 +8,13 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
3430F6711C45C930007473A6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6701C45C930007473A6 /* AppDelegate.swift */; }; 3430F6711C45C930007473A6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6701C45C930007473A6 /* AppDelegate.swift */; };
3430F6731C45C930007473A6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6721C45C930007473A6 /* ViewController.swift */; };
3430F6761C45C930007473A6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6741C45C930007473A6 /* Main.storyboard */; }; 3430F6761C45C930007473A6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6741C45C930007473A6 /* Main.storyboard */; };
3430F6781C45C930007473A6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6771C45C930007473A6 /* Assets.xcassets */; }; 3430F6781C45C930007473A6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6771C45C930007473A6 /* Assets.xcassets */; };
3430F67B1C45C930007473A6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6791C45C930007473A6 /* LaunchScreen.storyboard */; }; 3430F67B1C45C930007473A6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3430F6791C45C930007473A6 /* LaunchScreen.storyboard */; };
3430F6861C45C930007473A6 /* SampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6851C45C930007473A6 /* SampleTests.swift */; }; 3430F6861C45C930007473A6 /* SampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6851C45C930007473A6 /* SampleTests.swift */; };
3430F6991C45C949007473A6 /* Zip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3430F6961C45C93F007473A6 /* Zip.framework */; }; 3430F6991C45C949007473A6 /* Zip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3430F6961C45C93F007473A6 /* Zip.framework */; };
3430F69A1C45C949007473A6 /* Zip.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3430F6961C45C93F007473A6 /* Zip.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 3430F69A1C45C949007473A6 /* Zip.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3430F6961C45C93F007473A6 /* Zip.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3430F69F1C45C96A007473A6 /* master.zip in Resources */ = {isa = PBXBuildFile; fileRef = 3430F69E1C45C96A007473A6 /* master.zip */; }; 3467DAED1C4BADB700BA3DB8 /* FileBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3467DAEC1C4BADB700BA3DB8 /* FileBrowser.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
...@@ -66,7 +65,6 @@ ...@@ -66,7 +65,6 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
3430F66D1C45C930007473A6 /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3430F66D1C45C930007473A6 /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; };
3430F6701C45C930007473A6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 3430F6701C45C930007473A6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3430F6721C45C930007473A6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
3430F6751C45C930007473A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; 3430F6751C45C930007473A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
3430F6771C45C930007473A6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 3430F6771C45C930007473A6 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3430F67A1C45C930007473A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 3430F67A1C45C930007473A6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
...@@ -75,7 +73,7 @@ ...@@ -75,7 +73,7 @@
3430F6851C45C930007473A6 /* SampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleTests.swift; sourceTree = "<group>"; }; 3430F6851C45C930007473A6 /* SampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleTests.swift; sourceTree = "<group>"; };
3430F6871C45C930007473A6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 3430F6871C45C930007473A6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3430F6901C45C93F007473A6 /* Zip.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Zip.xcodeproj; path = ../../Zip.xcodeproj; sourceTree = "<group>"; }; 3430F6901C45C93F007473A6 /* Zip.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Zip.xcodeproj; path = ../../Zip.xcodeproj; sourceTree = "<group>"; };
3430F69E1C45C96A007473A6 /* master.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = master.zip; sourceTree = "<group>"; }; 3467DAEC1C4BADB700BA3DB8 /* FileBrowser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileBrowser.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -120,8 +118,7 @@ ...@@ -120,8 +118,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3430F6701C45C930007473A6 /* AppDelegate.swift */, 3430F6701C45C930007473A6 /* AppDelegate.swift */,
3430F6721C45C930007473A6 /* ViewController.swift */, 3467DAEC1C4BADB700BA3DB8 /* FileBrowser.swift */,
3430F69E1C45C96A007473A6 /* master.zip */,
3430F6741C45C930007473A6 /* Main.storyboard */, 3430F6741C45C930007473A6 /* Main.storyboard */,
3430F6771C45C930007473A6 /* Assets.xcassets */, 3430F6771C45C930007473A6 /* Assets.xcassets */,
3430F6791C45C930007473A6 /* LaunchScreen.storyboard */, 3430F6791C45C930007473A6 /* LaunchScreen.storyboard */,
...@@ -257,7 +254,6 @@ ...@@ -257,7 +254,6 @@
3430F67B1C45C930007473A6 /* LaunchScreen.storyboard in Resources */, 3430F67B1C45C930007473A6 /* LaunchScreen.storyboard in Resources */,
3430F6781C45C930007473A6 /* Assets.xcassets in Resources */, 3430F6781C45C930007473A6 /* Assets.xcassets in Resources */,
3430F6761C45C930007473A6 /* Main.storyboard in Resources */, 3430F6761C45C930007473A6 /* Main.storyboard in Resources */,
3430F69F1C45C96A007473A6 /* master.zip in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -275,7 +271,7 @@ ...@@ -275,7 +271,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
3430F6731C45C930007473A6 /* ViewController.swift in Sources */, 3467DAED1C4BADB700BA3DB8 /* FileBrowser.swift in Sources */,
3430F6711C45C930007473A6 /* AppDelegate.swift in Sources */, 3430F6711C45C930007473A6 /* AppDelegate.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
......
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "738-document-1.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "738-document-1@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "710-folder.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "710-folder@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Azc-ni-1lY">
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies> </dependencies>
<scenes> <scenes>
<!--View Controller--> <!--Navigation Controller-->
<scene sceneID="tne-QT-ifu"> <scene sceneID="qOO-wm-hTa">
<objects> <objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController"> <navigationController id="Azc-ni-1lY" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="He1-CR-cOP">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="dpw-R4-j8a" kind="relationship" relationship="rootViewController" id="X2C-fJ-xJK"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="vih-dz-uz2" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="234" y="152"/>
</scene>
<!--File Browser-->
<scene sceneID="mz0-lp-3R4">
<objects>
<viewController id="dpw-R4-j8a" customClass="FileBrowser" customModule="Sample" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides> <layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/> <viewControllerLayoutGuide type="top" id="edF-bh-llm"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/> <viewControllerLayoutGuide type="bottom" id="Gww-Pp-M3Q"/>
</layoutGuides> </layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC"> <view key="view" contentMode="scaleToFill" id="oeM-RL-OAb">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> <subviews>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3Y2-An-tBb">
<rect key="frame" x="0.0" y="556" width="600" height="44"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="rw6-VI-8wB"/>
</constraints>
<items>
<barButtonItem title="0 Selected" style="plain" id="dci-jS-Xlf">
<color key="tintColor" red="0.1333333333" green="0.1333333333" blue="0.1333333333" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</barButtonItem>
</items>
</toolbar>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="vkM-Ih-ncL">
<rect key="frame" x="0.0" y="64" width="600" height="492"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<outlet property="dataSource" destination="dpw-R4-j8a" id="EPE-vb-LNN"/>
<outlet property="delegate" destination="dpw-R4-j8a" id="kz0-pL-EP9"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="3Y2-An-tBb" firstAttribute="leading" secondItem="oeM-RL-OAb" secondAttribute="leading" id="2Ww-MM-Oc7"/>
<constraint firstAttribute="trailing" secondItem="vkM-Ih-ncL" secondAttribute="trailing" id="7gU-LQ-v0u"/>
<constraint firstItem="Gww-Pp-M3Q" firstAttribute="top" secondItem="3Y2-An-tBb" secondAttribute="bottom" id="9jg-8T-znb"/>
<constraint firstAttribute="trailing" secondItem="3Y2-An-tBb" secondAttribute="trailing" id="A9y-EZ-xWy"/>
<constraint firstItem="3Y2-An-tBb" firstAttribute="top" secondItem="vkM-Ih-ncL" secondAttribute="bottom" id="Fjn-9z-Bu6"/>
<constraint firstItem="vkM-Ih-ncL" firstAttribute="leading" secondItem="oeM-RL-OAb" secondAttribute="leading" id="ORH-IL-ORa"/>
<constraint firstItem="vkM-Ih-ncL" firstAttribute="top" secondItem="edF-bh-llm" secondAttribute="bottom" id="xmW-Hi-wfh"/>
</constraints>
</view> </view>
<navigationItem key="navigationItem" id="GLl-37-stv"/>
<connections>
<outlet property="selectionCounter" destination="dci-jS-Xlf" id="uVp-Mf-mdx"/>
<outlet property="tableView" destination="vkM-Ih-ncL" id="Pw4-pv-J01"/>
</connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="pqG-S7-8Xl" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="894" y="159"/>
</scene> </scene>
</scenes> </scenes>
</document> </document>
//
// FileBrowser.swift
// Sample
//
// Created by Roy Marmelstein on 17/01/2016.
// Copyright © 2016 Roy Marmelstein. All rights reserved.
//
import UIKit
class FileBrowser: UIViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var selectionCounter: UIBarButtonItem!
let fileManager = NSFileManager.defaultManager()
var path: NSURL? {
didSet {
if let filePath = path {
var tempFiles = [String]()
do {
self.title = filePath.lastPathComponent
tempFiles = try self.fileManager.contentsOfDirectoryAtPath(filePath.path!)
} catch {
if path == "/System" {
tempFiles = ["Library"]
}
if path == "/Library" {
tempFiles = ["Preferences"]
}
if path == "/var" {
tempFiles = ["mobile"]
}
if path == "/usr" {
tempFiles = ["lib", "libexec", "bin"]
}
}
self.files = tempFiles.sort(){$0 < $1}
}
}
}
var files = [String]()
override func viewDidLoad() {
if self.path == nil {
let documentsUrl = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
self.path = documentsUrl
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return files.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "FileCell"
var cell = UITableViewCell(style: .Subtitle, reuseIdentifier: cellIdentifier)
if let reuseCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) {
cell = reuseCell
}
guard let path = path else {
return cell
}
let newPath = path.URLByAppendingPathComponent(files[indexPath.row]).path!
var isDirectory: ObjCBool = false
fileManager.fileExistsAtPath(newPath, isDirectory: &isDirectory)
cell.textLabel?.text = files[indexPath.row]
if isDirectory {
cell.imageView?.image = UIImage(named: "Folder")
}
else {
cell.imageView?.image = UIImage(named: "File")
}
return cell
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
//
// ViewController.swift
// Sample
//
// Created by Roy Marmelstein on 13/01/2016.
// Copyright © 2016 Roy Marmelstein. All rights reserved.
//
import UIKit
import Zip
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
do {
let destinationPath = tempUnzipPath()!
let fileAbsolutePath = NSBundle.mainBundle().pathForResource("master", ofType: "zip")
let fileAbsoluteURL = NSURL(string: fileAbsolutePath!)!
print(destinationPath)
try Zip().quickUnzipFile(fileAbsoluteURL)
try Zip().quickZipFiles([fileAbsoluteURL], fileName: "zipTest")
}
catch {
print("oops")
}
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tempUnzipPath() -> NSURL? {
var path = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0]
path += "/\(NSUUID().UUIDString)"
let url = NSURL(fileURLWithPath: path)
do {
try NSFileManager.defaultManager().createDirectoryAtURL(url, withIntermediateDirectories: true, attributes: nil)
} catch {
return nil
}
return url
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment