What is the replacement of ObjC class method +load and +initialize in Swift?
Or how to do the same thing in Swift?
What is the replacement of ObjC class method +load and +initialize in Swift?
Or how to do the same thing in Swift?
This documentation may be helpful, if you're looking to call initializers on the Objective-C classes in UIKit and other Apple-provided APIs.
From that page, this short example. Instead of doing this in Objective C:
UITableView *myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
do this in Swift:
let myTableView: UITableView = UITableView(frame: CGRectZero, style: .Grouped)
If you're looking for how to initialize a Swift object that you've written, that's performed using a declared initializer like so:
class myClass: mySuperClass {
var x: init;
init(Int x, Int y) {
self.x = x;
super.init(y:y);
}
}
Ray Wenderlich's tutorials are a great jumping-off point for understanding the Swift language:
http://www.raywenderlich.com/74438/swift-tutorial-a-quick-start
I hope that helps.