4

Perfect - https://www.perfect.org - is a new web server which lets you use the same language on the server-side as you do on your the device. It will be compatible with the Linux version of Swift when it is released before the end of this year - presumably because it just uses Swift's standard library,

It has connectors for MongoDB, MySQL, PostgreSQL.

Currently, I'm developing an app using the Realm database in Swift. Will I be able to use Realm on the server-side too? Does it just use the Swift standard library?

cannyboy
  • 24,180
  • 40
  • 146
  • 252
  • Realm is designed for client side datastore, for server you should just use MongoDB, MySQL, PostgreSQL etc. – cezheng Nov 24 '15 at 11:47
  • Also, the Core of Realm is not open source, and you have to rely on realm.io to release a pre-built binary core for Linux – cezheng Nov 24 '15 at 11:49

1 Answers1

4

Realm offers so far two bindings for Cocoa-related development: Realm Objective-C and Realm Swift. The latter is based on the former and a shallow wrapper around the Objective-C APIs adopting types and protocols from the Swift standard library and exposing more convenient APIs. The reason for that architecture instead of a pure Swift binding is that Swift doesn't allow to interface C++ code, but Realm's underlying storage engine is based on that. This means that even with Realm Swift, you have Foundation as transitive dependency as we rely on it for e.g. RLMObject with Key-Value Coding, inter-operate with KVO, use Foundation's value types (NSNumber, NSArray, …).

So assuming that there won't be a Linux-compatible Foundation distribution shipping with the Linux version of Swift, using Realm on Linux would require a "pure" Swift binding of Realm, which isn't possible yet, an alternative Objective-C binding, which avoids Foundation, or a mature alternative implementation of Foundation, where GNUstep might be a candidate, but this is entirely untested from our side.

Update #1

Swift was open-sourced together with a Swift implementation stub of Foundation's APIs as a shim over OS APIs, so that it can be portably used on Linux and other platforms where Apple's Foundation is not available. This stub was filled since then with actual implementations by contributors to the project and is part of the Swift 3 release, so it can be used for pure Swift projects.

However this doesn't solve the general issue here that Realm Swift is not pure Swift and is based on Realm Objective-C. So it relies on the availability of the Objective-C runtime and Foundation.

Update #2

We recently announced the Realm Mobile Platform, which you can run on-premises or on the public cloud. So this makes it indeed possible to use Realm on Linux. But server-side access is so far exclusively supported on the Enterprise Edition with the Node.js binding.

marius
  • 7,766
  • 18
  • 30
  • There is an effort to create an open source alternative to Foundation - https://github.com/PureSwift/SwiftFoundation - which may be of interest. – cannyboy Nov 26 '15 at 11:29
  • I believe swift.org says Foundation is working in Swift 2.2 open source. – Jimmy Hough Jr Feb 12 '16 at 05:46
  • An update here was overdue. Even though there are efforts around making Foundation to pure Swift available, as long as Realm Swift is based on Realm Objective-C, it will rely on the Objective-C runtime and the specifics of Apple's Objective-C Foundation implementation. – marius Oct 04 '16 at 09:15