From objective-c to Swift, you have to be. (iii) sequence of Init

Source: Internet
Author: User

Objective-c the constructor, just return a self. You can initialize anything inside. In Swift's init function, put the super.init in front of you, and then initialize the contents of your code will be an error.

So:

Init (frame:nsrect) {    super.init (frame:frame)    subviewgroup = Gridviewgroup (Rows:9, Columns:9, gridview:self) }/***  Properties  ***/let subviewgroup:gridviewgroup

Is wrong.

What should it be like:

Init (frame:nsrect) {        Subviewgroup = Gridviewgroup (Rows:9, Columns:9, gridview:self)        super.init (frame:frame) }

Specific to the time of UITableView:

Override Init (Nibname nibnameornil:string?, bundle Nibbundleornil:nsbundle?) {        Self.tableview = UITableView (frame:cgrectmake (0, 0, cgrectgetwidth (rect), Cgrectgetheight (rect)), style: Uitableviewstyle.plain)                super.init (Nibname:nibnameornil, Bundle:nibbundleornil)        Dlog ()        Self.view.addSubview (self.tableview)        self.tableView.delegate = self        self.tableView.dataSource =        Self Self.tableView.allowsSelection = True    }

After Super.init can use self to give delegate, DataSource and so on to assign value.

From objective-c to Swift, you have to be. (iii) sequence of Init

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.