Reputation: 497
How to implement the below objective-c init method in swift
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil withName:(NSString *)name {
if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.name = name;
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];
}
return self;
}
Upvotes: 0
Views: 2649
Reputation: 21137
The equivalent would be this:
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?, name:String!)
{
self.init(nibName: nibNameOrNil, bundle: nibBundleOrNil);
self.name = name;
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "bg.png"));
}
You may have to implement required initializers if you get an error, but should not be needed if you use a later version than Beta5:
required init(coder aDecoder: NSCoder!) {
super.init(coder: aDecoder)
}
Upvotes: 1