-1

I'm new to Swift, come from Obj-C

I'm looking at the net, but to no avail ....

Obj-C in my project I created a class UIView (served as a notification that appeared red from the bottom) with a custom instancetype because through this allocavo the UIView directly in viewController with the parameters that I was interested .. Now I can not absolutely to create the translation of my code in Obj-C swift was trying to find a tutorial or something visual that I could figure out how to create a class with swift UIView without using a xib ...

Does anyone know any tutorial or example of class UIView without XIB in Swift?

My problem is that when I insert this custom init  

init (title:String, message:String) {
         // init
      }

first of all it returns an error because the compiler wants this also included

required init (coder aDecoder: NSCoder) {
         super.init (coder: aDecoder)
     }

My first question is this:

initWithCoder in obj-c was used only if my custom view was inserted in the storyboard ...

however in my case I would call all my custom view, in my view controller, through a simple line of code as I did in obj-c and that I was not allowed in because obj-c I used a custom instancetype without specifying them a initWithCoder it initWithFrame

I can not understand how this thing

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
kAiN
  • 2,559
  • 1
  • 26
  • 54
  • Turns out to be a duplicate of http://stackoverflow.com/questions/25126295/swift-class-does-not-implement-its-superclasss-required-members – matt Jun 12 '15 at 17:39

1 Answers1

1

To declare a class as a subclass of another class:

class MyView : UIView {
    // properties, methods such as `drawRect:`, etc., go here
}

To instantiate that class:

let v = MyView()

To configure that instance:

v.frame = // ....

To put a view instance into the interface:

self.view.addSubview(v)
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • So your question is actually why you have to add `required init(coder:)`? Do a search on Stack Overflow, this has been handled a thousand times here already. Don't be so lazy. – matt Jun 12 '15 at 17:37
  • For example: http://stackoverflow.com/questions/25126295/swift-class-does-not-implement-its-superclasss-required-members Or just implement it and move on. – matt Jun 12 '15 at 17:39