This project is a demonstration of organisation for an app that runs on both iOS and tvOS platforms using a unified code base. It is built using Swift 3.0 by iOS developers at ustwo.
In the demo, the user can access live feeds of the current status of different lines across Transport for London's network.
You should also then ensure you have all the required pods by running the following terminal command from the project folder:
$ gem install bundler
$ bundle install
$ pod install
You can then open the workspace file TFL Demo.xcworkspace
.
You will also need to register for a key for the TfL API. This should be included in the tflconfig.plist
file for use by the app. A template plist
file has been provided.
We have a single project with a target for each platform. There are three folders for source code and resources: Sources
which is for files common to all platforms, Sources-iOS
for files unique to iOS, and Sources-tvOS
for files unique to tvOS.
Data is fetched from TfL servers using the TFLRestAPI
shared instance. Each section of the API has its own definition (e.g. TFLLineAPI
) and Moya provider. For more information on the API itself, see TfL's website.
All constants are organised into struct
to provide grouping and scoping of the variables.
The app is based on a UISplitViewController
design pattern. The root view controller of the master side is ToolsTableViewController
. This allows the user to drill down into the correct tool to display the information desired.
There are two controllers that are used on the detail side of the split view - LineDetailViewController
and DashboardTableViewController
. The line detail shows the current status of a single line of transport on TfL's network. The dashboard scrolls through a list of all lines for a given mode of transport and displays their current status.
See also the Project Diagram for a high-level overview of the main controllers for the project.
There are two small extensions to first- and third-party frameworks. The first provides String
descriptions to Moya's Error
object. The second adds a function to UIColor
to specify whether the color is light or dark according to W3C specifications.
Most model objects are deserializations of the JSON returned from the TfL API. The model object exposes the data via constant properteries and is capable of deserializing itself directly from the JSON.
There are three enum
used to provide clarity around the mode of transportation - TFLModes
, TFLNationalRail
, and TFLUnderground
. Each of these also have convenience methods to assist with providing a branded UI for the given mode.
The last model object is Settings
which is where all NSUserDefaults
are stored for the app (such as the lines recently viewed by the user).
Extensions are provided on the TFLLine
and TFLLineSearch
model objects to provide configuration of table view cells in which to display their data.
- 24362789: Creating a
UISplitViewController
fully programmatically has layout issues when using aUINavigationController
on both primary and secondary views. The view on the secondary side extends under an opaqueUINavigationBar
until the screen is rotated. - 24363372: When you focus on a
UIBarButtonItem
that is an icon, even a system provided one such as Compose, the white icon disappears into the white background of the button. This is in contrast to text basedUIBarButtonItem
where the text changes colour to black on focus. - 24454686: A subclass of a generic superclass does not respond to a selector that points to a function that exists in an extension of the subclass. This prevents using a target-action pattern with functions in the extension.
Brunel is released under the MIT license. See LICENSE for details.