Twitter

Index

  • About: Into
  • Architecture I: Overview | Additional Modules | Dependencies Manager
  • Architecture II: Application | Domain | Core | Common | DesignSystem | DevTools
  • Tests: UI Tests | Unit Tests
  • Misc: Design Language | XcodeGen | SwiftLint and SwiftFormat | Profiling | CI/CD (Bitrise) | Install

About

Hit Happens is an open source app, built using SwiftUI and available on AppStore.

Intro

Hit Happens is built with SwiftUI using MVVM, and was mainly designed to integrate various frameworks and features in a well-organized structure with support for Unit Testing, UI Testing. Also makes use of other tools like XcodeGen, SwiftLint and SwiftFormat

SwiftUI because is Apple's current standart and offers several advantages like including a declarative syntax that simplifies UI design, real-time previews for faster iteration, and seamless integration with Swift for a unified coding experience while also enabling cross-platform development with a single codebase, significantly reducing development time and effort.

MVVM (Model-View-ViewModel) because separates concerns by dividing code into Model, View, and ViewModel, making maintenance easier. Also improves testability by isolating the ViewModel for unit tests, enhancing code reliability. It also boosts reusability, allowing ViewModels and Views to be used across different contexts. Additionally, MVVM simplifies data binding, integrating smoothly with SwiftUI and Combine for reactive and responsive user interfaces.

The navigation was inspired by Modular Navigation in SwiftUI: A Comprehensive Guide.

Architecture I

Overview

The app is built using Clean Architecture principles and separation of concerns, ensuring a maintainable and scalable codebase. It leverages dependency injection and interfaces for easy testing and seamless implementation changes.

  • App (Hit Happens): The main application containing Views, ViewModels, Managers (e.g., Analytics), Assets, and handling the app's life cycle.

  • Domain: Defines the app's Models and Interfaces.

  • Core: Implements the business logic, such as storage, caching and API requests, defined in the Domain.

  • DesignSystem: Houses definitions for the app's Fonts, Colors, and Designables (reusable UI components).

Additional Modules

There are 2 other modules not displayed for simplicity.

  • Common: A utility toolbox containing helper extensions, property wrappers, and other utilities. It has its own unit tests and can be used in any project as it has no dependencies. More info at https://github.com/ricardopsantos/Common

  • DevTools: Manages essencialy app logs, is its a module know across all other modules to facilitate logging.

This modular structure ensures each component is focused on a specific responsibility, promoting clean, efficient, and easily testable code.

Dependencies Manager

As package dependencies manager was choosen Swift Package Manager, as it simplifies dependency management and project organization for Swift developers. Also, enables you to easily add, update, and manage third-party libraries and frameworks. Integrated seamlessly with Xcode, Swift Package Manager promotes modularity, improves build performance, and ensures that your dependencies are up-to-date, making it an essential tool for modern Swift development.

The app philosophy emphasizes avoiding the addition of large dependencies for simple tasks (e.g., using Alamofire for a basic REST GET method). Instead, we carefully selected only three essential dependencies to handle complex or time-consuming (to implement) tasks:

  • KeychainAccess: "KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and macOS. Makes using Keychain APIs extremely easy and much more palatable to use in Swift."
  • TinyConstraints: "TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use."
  • Nimble: "A matcher framework that enables writing expressive and readable tests."

Architecture II

The project is organized into several key directories/targets, each serving a specific purpose: Application (Hit Happens), Domain, Core, Common, DesignSystem, DevTools, UnitTests and UITests

Application

It's the main application target. Contains the Views (scenes), ViewModels (glue betweeen Views and Logic), Coordinators (routing logic).

Domain

This target encapsulates the interface functionality of the application. Providing the Models and Protocols it define what the app can do and the data structures to do it.

  • Repositories: Local data storage protocols.
  • Services: Bigde betweens ViewModels and Network and where we can have more logic associated (eg. caching)

Core

This target implements the Domain functionalities, providing essential components such as:

  • Network: Remote communication implementations.
  • Repositories: Local data storage implementations.
  • Services: Bigde betweens ViewModels and Network and where we can have more logic associated (eg. caching)

Notably, Services, Repositories and Network are defined and implemented via protocols. The actual implementation is determined in the main app target, which is crucial for testing and ensuring scalable, maintainable code.

Common

A shared framework that includes extensions and utility functions used across multiple targets, promoting code reuse and modularity. Should not depend on any target, and should seamless work on any project.

DesignSystem

This target houses design-related components, ensuring a consistent and reusable visual style throughout the application. Also houses the applications Colors and Fonts

DevTools

Includes various development tools and utilities such as logging, facilitating smoother development and debugging processes.

Tests

The app includes comprehensive testing coverage with both UI Tests and Unit Tests. These tests are designed to cover a wide range of daily development scenarios, ensuring the app's reliability and performance. Additionally, we have incorporated measure/performance tests to monitor and optimize the app's efficiency.

This revision aims to clearly communicate the purpose and scope of the tests while emphasizing their importance in maintaining app quality and performance.

UITesting

The app includes UI Tests for views and routing logic

Unit Testing (ViewModels & Services)

The app ViewModels are built on a way that can be tested.

The app Services are built on a way that can be tested.

Misc

iClould Sync

Ligth / Dark mode support

Design Language

Design language in mobile apps refers to a set of guidelines and principles that define the visual and interactive style of an application. It includes elements like color schemes, typography, iconography, and spacing to ensure a cohesive and intuitive user experience. A well-defined design language helps maintain consistency, improve usability, and strengthen brand identity across different platforms and devices.

More about at Adding a Design Language to your Xcode project.

Custom Colors (for Ligth/Dark mode)

Custom Fonts

Custom Designables

XcodeGen

XcodeGen treamlines project management by allowing you to generate Xcode project files from a simple YAML or JSON specification. This approach reduces merge conflicts, ensures consistency across teams, and makes it easier to version control project settings. By automating project setup, XcodeGen enhances productivity and maintains a cleaner, more organized codebase.

SwiftLint and SwiftFormat

SwiftLint and SwiftFormat are essential tools for maintaining code quality in Swift projects. SwiftLint enforces coding style and conventions by analyzing your code for potential issues and inconsistencies, ensuring adherence to best practices. SwiftFormat, on the other hand, automatically formats your Swift code to conform to a consistent style, making it more readable and maintainable. Together, they help streamline development workflows and uphold code standards across teams.

Profiling

As of today, the project is free from memory leaks, ensuring stable performance even with extended use.

The app maintains a minimal memory footprint, consistently staying around 50-60 MB after adding 50 new events and navigating through various screens.

CI/CD (Bitrise)

Bitrise, a mobile-focused CI/CD platform, automates build, test, and deployment workflows to streamline development and accelerate quality app delivery—making it the chosen platform for this project.

Install

No need to install anything, as all app dependencies are managed via Swift Package Manager.

However, the project can be fully rebuilt with ./makefile.sh (for a total cleanup and conflict fixing) using XcodeGen. If you are not familiar with XcodeGen, please check Avoiding merge conflicts with XcodeGen.

The scripts can be found at Source/XcodeGen