Singleton vs Static FUNCTIONS

17 hours ago 1
ARTICLE AD BOX

Suppose I have a function that is used by multiple views. I could create a singleton so the function can be accessed anywhere:

class SharedFunctions { static let shared = SharedFunctions() func mySharedFunction() {…} }

Or I could create a static function:

class SharedFunctions { static func mySharedFunction() {…} }

But let's say the shared function is very complex (involving multiple other functions) AND the views that use it are only opened occasionally. Is there any memory advantage to using a singleton (that will only be created when the function is actually needed) vs a static function?

Read Entire Article