Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vapor server and companion iOS app examples

Tags:

vapor

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.

like image 352
GAllan Avatar asked Dec 08 '17 15:12

GAllan


2 Answers

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:

  • Separate as much application logic from the views as possible for placement into Swift Packages.
  • Consider using Swift and/or C libraries which are across platform.
  • Xcode sometimes requires extra manual steps like adding the C header files in the build phase.
  • Swift Packages can be generated as Xcode projects for use as subprojects in the iOS and macOS applications. The Swift Package subprojects serve as a workaround until iOS/macOS/tvOS applications can build with SPM.

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

SubprojectSynergyAPI

Resources

  • StackOverflow: How do I use Swift Package Manager with an existing macOS project? ⇗
  • StackOverflow: Vapor server and companion iOS app examples ⇗
  • Tutorial: "Sharing Swift Code Between iOS and Server Applications" ⇗
like image 123
l --marc l Avatar answered Nov 11 '22 04:11

l --marc l


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

like image 39
tobygriffin Avatar answered Nov 11 '22 05:11

tobygriffin