0

In Objective-C, we have:

+(void)load
{

}

What is the equivalent of this in Swift 4?

In Swift 1, we have:

override class func load() {

}

...but it's not available in Swift 4.2.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ramesh
  • 147
  • 1
  • 17
  • 4
    There is no equivalent func in Swift4 – Joakim Danielson Jul 16 '18 at 11:59
  • 4
    See for example https://stackoverflow.com/a/29104893/1187415: *"Support for overriding load was removed in Swift 1.2"* – Martin R Jul 16 '18 at 12:00
  • 1
    There is none as far as I know, all global initialization must somehow be done explicitly. Have a look at https://stackoverflow.com/questions/42824541/swift-3-1-deprecates-initialize-how-can-i-achieve-the-same-thing for a related discussion. – This https://stackoverflow.com/a/47621197/1187415 might help (i.e. use an Objective-C helper class), I don't know if that still works or is guaranteed to work in the future. – Martin R Jul 16 '18 at 12:04
  • @MartinR there is Magic in ObjC like `+(void)load { NSLog(@"Gott"); }` which is not dependent to initialzie, or anything, it invokes automatically. I am just looking the same in swift thanks btw :) . – Ramesh Jul 16 '18 at 12:10
  • 1
    I know what that does in Objective-C, but that feature does not exist in Swift. – Martin R Jul 16 '18 at 12:12

0 Answers0