1

I'm getting the error stated in the title where var updater is declared.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let destination = segue.destination as? ProductViewController,
            let index = tableViewProducts.indexPathForSelectedRow?.row {

            // Check whether postData array count is greater than index
            let updaterId = postData.count > index ? postData[index] : ""

            // Initialize "productsList" instance and assign the id value and sent this object to next view controller
            var updater = productsList(id: String?, p_name: String?, image: String?, audio: String?)
            updater.id = updaterId
            destination.updater = updater

here is my productsList VC:

import Foundation

class productsList {

    let id: String?
    let p_name: String?
    let image: String?
    let audio: String?

    init(id: String?, p_name: String?, image: String?, audio: String?) {
        self.id = id
        self.p_name = p_name
        self.image = image
        self.audio = audio
    }

}
1
  • Exactly at what line you are getting Issue.? Commented Apr 2, 2018 at 5:45

3 Answers 3

1

Use This

var updater = productsList(id: updaterId, p_name: nil, image: nil, audio: nil)

Instead of

var updater = productsList(id: String?, p_name: String?, image: String?, audio: String?)
Sign up to request clarification or add additional context in comments.

Comments

1

You have to pass string values (or nil) as the parameters not the type String?, that's what the error says.

Replace

var updater = productsList(id: String?, p_name: String?, image: String?, audio: String?)
updater.id = updaterId

with

let updater = productsList(id: updaterId, p_name: nil, image: nil, audio: nil)

and please conform to the naming convention that class names start with a capital letter.

1 Comment

Thank you so much. I have been staring at this issue for an hour or so, and only your answer helped me to realize what exactly I was doing!
0

This line is causing the issue

var updater = productsList(id: String?, p_name: String?, image: String?, audio: String?)

When you init your Object ie "ProductList" you must pass an actual value of your fileds "id", "p_name", "image" and "audio".

As now you are sending "String?", this is type of argument where your function is expecting a value for it.

So change it like

var updater = productsList(id: ID_OF_PRODUCT, p_name: NAMEOFPRODUCT, image: URLTOIMAGE/IMAGE, audio: AUDIOURL)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.