Swift for Xojo Developers : Introduction

A few years ago when Xojo released “Xojo for iOS”, I was excited… until I say everything that was missing or constrained with the product. It was then that I decided to teach myself Swift. And one thing that I did, both to teach myself things, but also to give me tools to use in the future, I began writing a number of “frameworks” [not just a term, not a true Swift Framework (yet) ]

What I plan on doing here, unless there is no interest, is to post a series of these code modules, almost all of which wrap Swift code into methods or functions that mimic as closely as possible a Xojo method or function.

The first one will involve File Management
here are the signatures for the classes that will be in the first few postings

class folderitem {
    var name : String {
    var parent           : folderitem 
    var displayName      : String    
    var exists           : Bool     
    var isFolder         : Bool     
    var isWriteable      : Bool    
    var isReadable       : Bool    
    var lastErrorCode    : Int    
    var lastErrorMessage : String   
    var count        : Int  

    var length : Int    
    var modificationDate : String 
    var creationDate     : String 
    var path             : String 
    var URLpath          : String
    var URL              : URL    

    func child(_ name:String) -> folderitem 
    func item(_ index:Int) -> folderitem? 
    func CopyTo(name:String) 
    func MoveTo(destination:String) 
    func CreateAsFolder() 
    func Delete() 
}

class SpecialFolderClass {
    var Documents : folderitem 
    var ApplicationSupport : folderitem 
    var Resources : folderitem 
    var Temporary : folderitem 
}

class textOutputFile {
    func Append(_ f : folderitem ) 
    func Create(_ f : folderitem ) 
    var lastErrorCode     : Int    
    var writeError        : Bool    
    var lastErrorMessage  : String  
    func close() 
    func writeLine(_ data : String) 
    func write(_ data : String) 
}


class textInputFile {
    var lastErrorCode     : Int     
    var readError         : Bool   
    var lastErrorMessage  : String 

    func open(_ f : folderitem ) 
    var EOF : Bool 
    func close() 
    var readALL : String 
    var readLine : String? 
}

The first one will be FOLDERITEM… once I finish adding all the required comments.
Note this comments will attempt to follow the Xcode Markdown syntax

Also, if anyone sees ANYTHING that could be made better, PLEASE let me know.
Some of these were written back in Swift2.0 and things have changed between now and then.

4 Likes

If anyone has any questions about any of these classes, or would like the Xcode source to anything I have posted, just send me a PM.

Have to confess that I am so busy right at the moment that I’ve only skimmed most of the posts

Need longer days - anyone in for a 40 hour day ? maybe metric days of 100 hours, weeks of 10 days, and months with 10 weeks ?

1 Like

I dread to think what the lack of sleep I subject myself is doing to me in the long run. It’s the only way to cram everything into the day though.

1 Like

I will be interested after Xmas caught up with deadlines etc

DaveS … I’m intrigued by Swift; it would be an easy language for me to pick up.

What kind of tooling do you personally use? Are there decent visual UI designers? RemObjects looks interesting and brings the language to Windows, even Visual Studio. Any experience with that, or is Xcode considered safer territory?

Just curious what you find stable and useful.

I thing @Garry has been using RemObject Swift toolchains

I use Xcode, and a UIDesigner I wrote myself (translates Xojo to Swift actually).

1 Like

If you are on Mac, Xcode is definitely an interesting and very powerful IDE.
On Win, Swift can be used in Visual Studio (haven’t tried this, but have a look at Swift’s website).

However, it is my understanding that there is still no easy way to build a GUI for Windows using Swift. Xcode provides Interface Builder (drag-n-drop, and very complex in my opinion), or the GUI can be built 100% in code (which is how I do it)

RemObjects has a Windows IDE and a Visual Studio plugin. I’m not clear on whether there’s a visual designer or how mature it is. Their MacOS IDE is supposed to be the exact equivalent of their Windows IDE … they call them Fire and Water, lol.

But in using RemObjects you are using their compiler technology and toolchain, which of course they brag up like it’s the Second Coming. So for Swift it seems to come down to XCode vs RemObjects.