From 467c7a4f7069e1ac6d4cd4e38a1e44e2e8906f1f Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Sat, 5 Nov 2016 20:02:42 +0200 Subject: [PATCH] Add Swift 3 override mention --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index d42bbe0..5bee03d 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,14 @@ This approach supports lazy initialization because Swift lazily initializes clas Class constants were introduced in Swift 1.2. If you need to support an earlier version of Swift, use the nested struct approach below or a global constant. +If you are using Swift 3.0.1 or above, the `init` method definition must be preceeded by the [`override` keyword][override]: + +```swift + override init() { + println("AAA"); + } +``` + ### Approach B: Nested struct ```swift @@ -63,3 +71,5 @@ class SingletonC { ``` I'm fairly certain there's no advantage over the nested struct approach but I'm including it anyway as I find the differences in syntax interesting. + + [override]: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Inheritance.html#//apple_ref/doc/uid/TP40014097-CH17-ID196