This is one of the quick messages with crypto errors. As far as I can tell, since the left and right sides are not the same ( Optional<String> vs String ), it is best to assume that you meant that both sides were UInt8 .
To understand that UILabel.text is optional, you can do something long:
actionLabel.text = (actionLabel.text ?? "") + "\(action.name) |"
This gets the current value or an empty string and adds text. You can also avoid the problem functionally:
actionLabel.text = join(" | ", map(actions, { $0.name }))
Update
Regarding an iterative solution with additional | at the end of the "", I tried to illustrate the solution of only the line causing the error. Your published code also makes the assumption that actionLabel was initially empty and has some (probably insignificant) performance overhead when setting label text several times.
A complete iterative approach might look something like this:
var text = "" for action in actions { if text.isEmpty { text = action.name } else { text += " | \(action.name)" } } actionLabel.text = text
Mapping and concatenation are such common operations that most languages have clean, concise ways to do this without iteration. For example, I would recommend the following in Objective-C:
actionLabel.text = [[actions valueForKeyPath:@"name"] componentsJoinedByString:@" | "];
source share