sk123
sk123

Reputation: 600

Result values in '? :' expression have mismatching types '()' and 'String?'

I have no idea what i am getting wrong here, i am basically checking if a value is coming back nil then populate the UILabel with a standard number or else if the value comes back, i populate the UILabel with the value.

account.agent.ddi == "" || account.agent.ddi == nil ? self.ddiLabel.text = "02039909000" : self.ddiLabel.text =  account.agent.ddi

Upvotes: 1

Views: 328

Answers (2)

Shehata Gamal
Shehata Gamal

Reputation: 100503

It's heavy for the the compiler without ()

account.agent.ddi == "" || account.agent.ddi == nil ? ( self.ddiLabel.text = "02039909000" ) : ( self.ddiLabel.text =  account.agent.ddi)

Upvotes: 1

David Rönnqvist
David Rönnqvist

Reputation: 56625

Since you're assigning to self.ddiLabel.text in both of the cases you can separate the assignment from the ?: operation, making the return type String in both cases

ddiLabel.text = account.agent.number == "" || account.agent.ddi == nil ? "02039909000" : account.agent.ddi

Upvotes: 2

Related Questions