Concept for organizing View and Data layers within SwiftUI App

Overview

SwiftUI MVVM Concept

It is not about how to create Lists and Charts and View design. It's about possibility how to organize View and Data layers within SwiftUI App. It's not about specifics how to implement Data layer. Apply your own stack to the concept.

Organizing View and Data layers within SwiftUI App

Concept based on protocols. It is not "typical" MVVM for SwiftUI as you might find on the web.

Aspirations

  • Decouple View and Data layers and loosen dependencies between them
  • Easily change a data source from Web to File etc.
  • Easily change a data source format from JSON to XML, XML to CSV etc.
  • Share the same data source between different View presentations(Grid, Chart other components)
  • Maximize reusing code between different projects
  • Easily split the development of View and Data layers between independent developers
  • Testability

The principle of the concept is 1-2-3

1. Model

  • Define Model
struct User: Model {    
    let id: Int    
    let name: String
    let age: Int
}

2. Store

  • Define Store

It's store parameter for UniversalList View in the example

  • Proxy is defining a communication layer. Proxies are used by Store to handle the loading and saving of Model data
  • Reader is used to interpret data to be loaded into a Model instance
RemoteStore(
    proxy: File(
        reader: Json(),
        fileName: fileName
    )
)

3. View

  • Define View
UniversalList(
    store: store,
    content: content,
    toolBar: toolBar
)

content parameter is a template for creating View depicting an entity toolBar set of predefined controls to manage View plus you can add your cystom set

SwiftUI template Development Architecture Designing with Protocols

App stores are assembled in AppViewModel In the code example. Two views (UniversalList, BarChart) implementing different presentation (Chart and List) share the same Store.

Package Description
Data The package is comprised of set of classes, structs and protocols for organizing infrastructure for a data layer in apps.
Service The package is comprised of set of classes, structs and protocols for implementing different services like authentication etc.
Ui The package is comprised of view components that might be shared between diff projects.

Writer is not implemented in the code example. It is placed on the diagram to show the comprehensiveness of the solution for any type of communication with remote sources

Class-Struct Diagramm

UI behavior

Click or tap the picture to watch the expected UI behavior of the example

  • Shared source of data with different presentations
  • Views control
  • Dynamically added Views
  • Master detail view
  • Sign in sign out

click to watch expected UI behavior for the example

Requirements

  • Xcode Version 12.5+ Swift 5.3
You might also like...
Much a-do with compositional layouts and diffable data sources.

Film Goal Reflect upon decisions made on my last project Films (submitted in July of 2019) and make improvements on my findings. Be more pragmatic wit

This is a basic twitter app to view, compose, favorite, and retweet tweets.
This is a basic twitter app to view, compose, favorite, and retweet tweets.

Twitter - Part II This is a basic twitter app to view, compose, favorite, and retweet tweets. Time spent: 6 hours spent in total User Stories The foll

Example Xcode swift iOS project for Core Data + iCloud syncing
Example Xcode swift iOS project for Core Data + iCloud syncing

iCloudCoreDataStarter Hello, I'm Chad. For the last several months I have been working on Sticker Doodle, an app you should go download right now! In

This is an Instagram clone with a custom Parse backend that allows a user to post photos, view a global photos feed, and add comments!
This is an Instagram clone with a custom Parse backend that allows a user to post photos, view a global photos feed, and add comments!

Parstagram - Part II This is an Instagram clone with a custom Parse backend that allows a user to post photos, view a global photos feed, and add comm

Library that holds multiple books loaded from json in a scroll view where each book can be tapped on, favorited, rated, and opened to read
Library that holds multiple books loaded from json in a scroll view where each book can be tapped on, favorited, rated, and opened to read

Library that holds multiple books loaded from json in a scroll view where each book can be tapped on, favorited, rated, and opened to read. If a book is a favorite, an orange star appears on the book's cover. Page number, favorites, and ratings are saved for each session of the app.

SwiftUI Project built using the fundamentals of SwiftUI that I have learned.

GhibliLog About: I wanted to test my ability to create an application with a responsive SwiftUI interface that would format and display data pulled fr

Todolist-swiftui - An example of using SwiftUI with CoreData

todolist-swiftui An example of using SwiftUI with CoreData Installation Install

Challenge-swiftui-space - Project for SwiftUI Dev Sprints on Devpass
Challenge-swiftui-space - Project for SwiftUI Dev Sprints on Devpass

SwiftUI Challenge - Space App 🚀 Neste desafio, desenvolveremos a interface de u

Owner
Igor
Igor
The concept took third place in the Design Concept Award contest Season 1 in 2021.

SpringAnimation Developed by Yurii Sameliuk as part of the You are launched "Design Concept Award" contest Season #1. SpringAnimation demo. Inspired b

You are launched 5 Jul 10, 2022
The concept won first place in the Design Concept Award contest Season 1 in 2021.

TallyCounter Developed by Vladyslav Fil as part of the You are launched "Design Concept Award" contest Season #1. Tally Counter Micro-Interaction demo

You are launched 3 Jan 15, 2022
The concept won first place in the Design Concept Award contest Season 2 in December 2021.

SwiftUI-ChristmasGift Developed by Alex Kryvodub as part of the You are launched "Design Concept Award" contest Season #2. ChristmasGift demo. alex.mp

You are launched 5 Jan 12, 2022
The concept took second place in the Design Concept Award contest Season 2 December 2021.

SwiftUI-UrlaunchedMerryChristmasCard Developed by Yurii Sameliuk as part of the You are launched "Design Concept Award" contest Season #2. MerryChrist

You are launched 6 Jun 17, 2022
The concept took third place in the Design Concept Award contest Season 2 in December 2021.

SwiftUI-UrlaunchedLaunchScreen Developed by Vladyslav Fil as part of the You are launched "Design Concept Award" contest Season #2. Animated Launch Sc

You are launched 5 Jan 12, 2022
Task App for Swift that Persist Data with Core Data (iOS)

Originally by: Michael Crump Updates for Xcode 10 with Swift 4.2 by David Phillip Oster

Michael Crump 16 Aug 3, 2021
Advanced Catalyst Example with sidebar, list view, SwiftUI detail view, toolbar & AppKit bundle

Advanced Catalyst Example This is an example of a Catalyst app using a three-column layout, with a primary toolbar. It includes topics such as: Drag &

Steven Troughton-Smith 214 Sep 19, 2022
iOS Application that gets the trending repositories data from Github API and displays it in a tableView.

Github-Trending-Repos iOS Application that gets the trending repositories data from Github API and displays it in a tableView. Follows MVC architectur

Anshul Koshyari 0 Oct 30, 2021
Code Challenge - Using Alamofire is a Swift-based, HTTP networking library, also Codable for Data Model and Combine Framework .

Code Challenge ##Using Alamofire is a Swift-based, HTTP networking library, also Codable for Data Model and Combine Framework . Alamofire is one of th

Eng Angelo Saber 0 Nov 24, 2021