I want to convert the below Objective C code to Swift. But struggling to do that. Could some swift experts help me please.
-(id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
NSURL *url = [NSURL URLWithString:@”http://www.apple.com”]
self.request = [NSURLRequest requestWithURL:url];
}
return self;
}
答案 0 :(得分:1)
Simple as that:
required init?(coder aDecoder: NSCoder) {
//your code
}
答案 1 :(得分:0)
required init?(coder: NSCoder) {
/*
* If you need call super.init(coder: coder)
* make sure the father class implement this method manually
* Otherwise use super.init() to instead
*/
super.init(coder: coder)
let url: URL = URL(string: "http://www.apple.com")!
let request: URLRequest = URLRequest(url: url)
}