1

I have a custom view derived from UIView,in init method like this:

- (instancetype)init
{
    if ([super init])
    {
        self.frame = [UIScreen mainScreen].bounds;
or self = [[UIView alloc]init];
    }    
    return self;
}

It never shows the error, but when I use Swift

init() {
    self.frame = UIScreen.mainScreen().bounds
}

The compiler tells me:

Super.init isn't called on all paths before returning from initialiser

then I add super.init() and the compiler tells me:

Convenience initializer is declared here (UIKit.UIView)

How can I use some initial method like self = [[UIView alloc]init]; in a Swift init method?

Alex Zavatone
  • 4,106
  • 36
  • 54
Dean Lee
  • 781
  • 2
  • 7
  • 13
  • 1
    Why don't you do `super.init(frame: UIScreen.mainScreen().bounds);` like there: http://stackoverflow.com/questions/24339145/how-do-i-write-a-custom-init-for-a-uiview-subclass-in-swift ? – Larme Jun 24 '16 at 09:50

1 Answers1

0

Try with this...

init()
{
    super.init(frame: UIScreen.mainScreen().bounds)

    // Other initialization operations...
}
Adolfo
  • 1,862
  • 13
  • 19