Skip to content

A simple implementation of a swift macro that allows you to create singletons in a moment

License

Notifications You must be signed in to change notification settings

ivanglushko/singleton-swift-macro

Repository files navigation

⚙️ Sigleton Macro for Swift classes

This repository contains a simple implementation of a swift macro that allows you to create singletons in a more concise way.

Usage:

  1. Add a package dependecy to your project
  2. In order to apply a macro use @Singleton annotation before the class definition. Like this:
import Singleton

@Singleton
class MyClass {
    // class contents...
}
  1. The macro will expand the class definition to a singleton implementation like this:
import Singleton


class MyClass {

    static let shared = MyClass()

    private init() {
    }
}
  1. Thus making a MyClass.shared instance of the class available out of the box.

About

A simple implementation of a swift macro that allows you to create singletons in a moment

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages