This document discusses application architecture using Swift language features. It promotes principles like single responsibility and communication patterns. It also discusses common architectural patterns like MVC and dividing problems into layers. Specific topics covered include using table views, facades for dependencies, defining application layers, and how layers can communicate. The document also contrasts mutable and immutable models and how to handle changes when using immutable structs.
12. TABLE VIEWS
▸ Data Source is just a protocol
▸ Android: ListAdapter
▸ WWDC 2014,
Session 232: Advanced User Interfaces with
Collection Views
13. FASCADES FOR DEPENDENCIES
A facade is an object that provides a simplified interface to a larger
body of code, such as a class library
You can use a protocol and class extensions to ensure interface
conformance in your objects.
15. HOW DO LAYERS COMMUNICATE?
▸ Delegate
▸ Event Bus
▸ References
▸ Protocols
16. SERVICE
A service is a self-contained unit of functionality.
▸ CLLocationManager
▸ CMMotionManager
17. SERVICE
class ViewController: UIViewController {
@IBOutlet var tableView: UITableView!
let messageService = MessageService.sharedInstance
let locationService = LocationService.sharedInstance
}
19. MUTABILITY
class Message: NSObject {
var text = ""
var recipient: String?
}
var messages: [Message]
▸ there might be a message without a recipient
▸ properties might change at any given time
▸ react to notifications and KVO
20. IMMUTABILITY
struct Message {
let text: String
let recipient: String
}
let message = Message(text: "Hello World!", recipient: "Marc")
▸ properties can’t change
▸ structs are value types - methods become side effects free!
▸ value types are thread safe by default
22. HOW TO CHANGE THE UNCHANGEABLE?
▸ have a service for model operations
▸ callbacks deliver new object instead of updated one
func loadMessages(completion:(([Message]?, NSError?)->())?)
▸ attach new objects to NSNotification payload