Tag: Design Pattern

  • The Observer Pattern in Swift

    The Observer Pattern in Swift

    The Observer pattern is a design pattern that allows objects (observers) to register to receive notifications from another object (the subject). In Swift, the Observer pattern can be implemented using the ‘NotificationCenter‘ class and the ‘addObserver‘ method, like this: The SomeObserver class has a startObserving method that registers the handleNotification method as an observer of…

  • The Singleton Pattern in Swift

    The Singleton Pattern in Swift

    The Singleton pattern is a design pattern that ensures that only one instance of a class can be created, and provides a global point of access to that instance. In Swift, the Singleton pattern can be implemented using a static property and a private initializer, like this: In this example, the Calculate class is implemented…