Newbie Question

Hi there

Happy New Year to everyone!

I am trying to do something super simple using Swift - we are changing our infrastructure and the new environment requires me to work with Swift. Needless to say, I am a complete newbie and a bit lost on where to go first / start.

The scenario is this: we take a backup of our db every night and then need to move that backup to an offsite server for redundancy. So it’s a get get file, cp file, save file idea. Nothing more.

Any thoughts on how to go about this or where to start looking for resources?

Thank you!
Sherri

I am trying to do something super simple using Swift - we are changing our infrastructure and the new environment requires me to work with Swift. Needless to say, I am a complete newbie and a bit lost on where to go first / start.

The scenario is this: we take a backup of our db every night and then need to move that backup to an offsite server for redundancy. So it’s a get get file, cp file, save file idea. Nothing more.

Any thoughts on how to go about this or where to start looking for resources?

If you're looking at opening files and/or running external commands, you're going to need to use the C library (Darwin on Mac, Glibc on Linux) or, if you're on the Mac, Foundation. Which are you looking at here?

···

--
Brent Royal-Gordon
Architechies

Unfortunately this isn’t the sort of thing that’s super simple with Swift right now, at least not on Linux. Swift doesn’t have a mature standard library yet for tasks like I/O, because on Apple platforms it’s been able to use the underlying Cocoa frameworks. There’s a project to create a new cross-platform standard library, but it’s in the early stages.

It’s definitely possible to call directly into C standard library functions like fopen and fwrite, but it requires knowledge of how C bridging works, and involves using special types like UnsafePointer. (There was a thread here a few weeks ago about how to do file I/O, if you want to search for it.)

Six months from now, doing some file copying with Swift should be a no-brainer! But for now I’d avoid it as a newbie task. If you just want a project to learn the language itself, I’d suggest doing some “CS 101” type exercises like implementing binary trees or computing prime numbers. Apple’s Swift book has some interesting sample programs in it too.

—Jens

···

On Jan 4, 2016, at 9:07 AM, Sherri McGurnaghan via swift-users <swift-users@swift.org> wrote:

I am trying to do something super simple using Swift - we are changing our infrastructure and the new environment requires me to work with Swift. Needless to say, I am a complete newbie and a bit lost on where to go first / start.