One of the reasons advocates of swift server side give for the use of swift is that it allows iOS developers to develop backends for their apps. But, I do not see many example of this usage pattern.
There is a chat-ios example but that is using websockets.
Are there any server and companion iOS app examples available?
One of the difficulties of using a custom server is handling the possible poor comms in iOS app usage. I would like to see if any project out there have handled this well.
One of the reasons for using parse/firebase is the builtin client side support for syncing/retry. Are there any resources/frameworks for client side apps that can be used to give this reliability for custom backends.
I've been using Swift Packages for both iOS/macOS clients and Vapor backend development for some time. I'm in the process of gathering the lessons learned into a generic set of Open Source repositories: VaporExampleLabs/Synergy*
.
It is possible to have Swift Packages which can be used on the Swift server side, and on iOS devices and in macOS applications. A greater separation between the views (Vapor View
, iOS UIView
, macOS NSView
) and underlaying application logic, allows more code to be shared in Swift Packages across the platforms.
The VaporExampleLabs/Synergy*
collection of packages & projects provides various working pieces of how to setup a Vapor server, iOS device client and a macOS client to use the same Swift Packages.
Each part highlights some key findings for the use of a Swift code shared in both Server backend and Client device software development.
Main Obervations:
Note: The Synergy set of projects and packages are still a work in progress for gathering lessons learned. The goal is to create a full (self-contained) set of backend-to-client connected examples sharing common Swift Packages.
SynergySqliteC
Sometimes lower level libraries are not common between the server and device. For example, the database Object Relationship Model (ORM) is different for Vapor and iOS/macOS have CoreData. Vapor provides Fluent. iOS/macOS provides CoreData.
This example illustrates direct use the SQLite C source code at the lowest level.
SynergySqliteC ⇗
shows how to setup a cross platform C library into a Swift Package.
A pure C package may require manual addition of the *.h files to the project treee for building in an Xcode project.
SynergySQLiteFramework
SynergySQLiteFramework ⇗
provides a generic Swift framework for using the C-base Swift Package SynergySqliteC
.
SynergyAPI
SynergyAPI ⇗
provides the Codable interface for the collection of Synergy applications. Uses the generics SQLite package SynergySQLiteFramework
.
SynergyVapor
SynergyVapor ⇗
provides an example Vapor web application which uses the SynergyAPI
.
Synergy Clients
Synergy ⇗
provides both an iOS and macOS client Xcode projects. Both the iOS and macOS clients use the SynergyAPI
package.
Swift Packages in iOS/macOS Applications
Swift Package Manager Project stated the following prior to 2019.06.03:
Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.
On 2019.06.03, the Swift Package Manager Project was updated to indicate some SPM support is present in Xcode 11.
Xcode 11 integrates with libSwiftPM to provide support for iOS, watchOS, and tvOS platforms.
Even though the Swift Package manager can not directly create an iOS or macOS application, Swift Packages can still be used as subprojects in the respective Xcode application projects.
cd SynergyAPI
swift package generate-xcodeproj \
--xcconfig-overrides Package.iOS.xcconfig \
--output SynergyAPI_iOS
swift package generate-xcodeproj \
--xcconfig-overrides Package.macOS.xcconfig \
--output SynergyAPI_macOS
This official list of Vapor projects contains a couple of iOS/server project pairs.
This is probably the best example from that list.
Server: https://github.com/cocoaheadsru/server
Client: https://github.com/cocoaheadsru/application
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With