Swift for Xojo Developers - Part 13 : OpenDialog/SaveDialog for macOS

I’m not going to attach the code for this one directly (it almost 500 lines)
But it is a Swift module that closely replicates the operation of all Xojo File Dialogs
It does require the TextFile module I posted a number of weeks ago, as it is dependant on the “folderitem” class contained there.

Functions

func GetOpenFolderItem(filter:[String]) -> folderitem? {}
func GetSaveFolderItem(filter:[String],defaultName:String="") -> folderitem? {}
func SelectFolder() -> folderitem? {}

Classes

class OpenDialog : templateOpenDialog {}
class SaveAsDialog : templateSaveDialog {}
class SelectFolderDialog : templateOpenDialog{}

These work almost identically to the same named function or class in Xojo, with one outstanding difference.

Each takes an array of File Extensions instead of the FileType as in Xojo. This Swift code then converts those to the corresponding UTI and uses that information.
For example if you indicated

let f = GetSaveFolderItem(["jpg"],"mypic.jpg")

if would actually allow [“jpeg”, “jpg”, “jpe”] as they all belong to the same base UTI

Note : the UTI code was written by Hiroki Kato and found on GitHub

Do the dialogs etc allows for “configuration”
So a file & / or folders can be selected at one time and multifile selections ?

yes, yes they do
while not 100% identical… the biggest variance is how “filetypes” are defined…

   class templateOpenDialog{
    public var actionButtonCaption : String {
    public var count : Int { 
    public var filter : [String] {
    public var multiSelect : Bool {
    public var initialDirectory : folderitem? {
    public var promptText : String {
    public var result : folderitem? {
    public var Item : [folderitem] { 
    public func showModal() {
    public func showModalWithin()
}

class templateSaveDialog{
    public var actionButtonCaption : String {
    public var filter : [String] {
    public var suggestedFilename : String {
    public var initialDirectory : folderitem? {
    public var promptText : String {
    public var result : folderitem? {
    public func showModal() {
    public func showModalWithin(
}
1 Like