1. 程式人生 > >Browsing files in your iOS app in Swift

Browsing files in your iOS app in Swift

Browsing files in your iOS app in Swift

Introducing FileBrowser

Last month I released an open source iOS framework for zipping and unzipping files called Zip.

For Zip’s example project, I wanted a quick Cocoapod that will display the file system with a nice UI and will let users use and observe Zip in action. Despite my best Googling skills, I couldn’t find such framework and ended up writing a very quick and simple implementation.

Browsing an app’s file system and interacting with files is incredibly useful (either as production UI or for debugging purposes). I decided to make an iOS file browser my next Swift project…

Meet FileBrowser

FileBrowser is a simple Swift framework to view and select files in your app’s file system. It comes with a familiar UI (based on OS X’s Finder) and powerful features like peek & pop previews and search. It’s as easy to display as:

let fileBrowser = FileBrowser()
self.presentViewController(fileBrowser, animated: true, completion: nil)

When a file is selected, the default behaviour is to push a preview viewcontroller with sharing options. You can provide an alternative behaviour by using a simple closure:

fileBrowser.didSelectFile = { (file: FBFile) -> Void in
print(file.displayName)
}

There are even more customisation options like changing the root folder and excluding specific file types or file paths.

Check it out on: