Getting wrong "Ambiguous reference" in initAsk Questions

 Posted on 27 days ago

Hi

I want to add an init function to a UIViewController to ensure that a property that I require is always going to be set. The code is this:

  1. class XBSelectRecord: UIViewController {  
  2.           
  3.     convenience init(labelXXX: String?)  
  4.     {  
  5.         self.init(nibName: "XBSelectRecord", bundle: nil)    ! Ambiguous reference to member 'init(labelXXX:)'  
  6.         self.heading = labelXXX  
  7.     }  
  8.       
  9.     required init?(coder: NSCoder) {  
  10.         fatalError("init(coder:) has not been implemented")  
  11.     }  

Clearly that should not be ambiguous. Can anyone explain what I am doing wrong here?

Share On: facebook gplus twitter
profile
Asked by Will Smith on 27 days ago Score: 54 points
Add Comment:

Comments

2 Answers

0 Corrected Answers
Aproved Answers
1
Profile
Answered by Steve Summit on 11/1/2019 7:53:03 AM Score: 52 points

So your `XBSelectRecord` does not have an initializer named `init(nibName:bundle:)`, which is causing the error.

You may need to implement the initializer explicitly:

  1. class XBSelectRecord: UIViewController {  
  2.     var heading: String?  
  3.       
  4.     convenience init(labelXXX: String?) {  
  5.         self.init(nibName: "XBSelectRecord", bundle: nil)  
  6.         self.heading = labelXXX  
  7.     }  
  8.   
  9.     override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {  
  10.         super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)  
  11.     }  
  12.     required init?(coder: NSCoder) {  
  13.         fatalError("init(coder:) has not been implemented")  
  14.     }  
  15. }  

 

Or else, remove both overrides:

  1. class XBSelectRecord: UIViewController {  
  2.     var heading: String?  
  3.       
  4.     convenience init(labelXXX: String?) {  
  5.         self.init(nibName: "XBSelectRecord", bundle: nil)  
  6.         self.heading = labelXXX  
  7.     }  
  8. }  

Comments

Add Comment:
Aproved Answers
-3
Profile
Answered by AnthonyBak on 10/29/2019 6:28:07 AM Score: 13 points
如何规避风险并获得最大的投资回报? 有更好的解决方案! 短期投资带来最大利润! 投资期限2天。 投资利润+ 10% 可以在官方网站上注册国际投资基金: https://www.crypto-mmm.com/?source=xbtc

Comments

Add Comment:

Post Your Answers

Existing Members

Sign in to your account
Email Address
Password
New Member?
Sign up and complete profile
Full Name
Email Address
I have read and agree to the Terms of Service and Privacy Policy
Please subscribe me to the StoodQ newsletters
Guideline to answer a question:

Useful tips to submit your answer
Please read below guidelines before you submit your answer for question.

  • Read and understand question for which you are submitting your answer.
  • Try to avoid grammatical and spell mistake while answering.
  • Do not post any irrelevant information in your answer.
  • Explain your answer with example or any reference link to help who posted question.
  • If you find irrelevant question, please report it to support. Click here to contact support.
  • You agree to the privacy policy and terms of use to submit any contents.

Note: StoodQ is online developers community which helps developer for their difficulty, lets help them with your value contribution.