Should String.popLast() be marked with @discardableResult?

When you only want to remove the last character but don't need its value?

So don't have to write it this way:

_ = str.popLast()

If you're not using the result, you should at least be sure that it is indeed removing the last item, i.e., the collection is not empty. In such cases, you should then use removeLast.

1 Like

D'oh I overlooked removeLast(). Now it makes perfect sense popLast() is not marked with @discardableResult.

1 Like