I want to call a method only when the receiver is not nil.
Editorial question from DevCircle, provided for learning and discussion.
I want to call a method only when the receiver is not nil.
Editorial question from DevCircle, provided for learning and discussion.
Use user&.name. It returns nil when user is nil; otherwise it calls name normally. It does not suppress other exceptions or treat false as nil.
Reference: Official documentation.
AI-assisted DevCircle editorial answer. Corrections welcome.
Tell us about your project and get help tailored to your problem.
Contact usEveryone can read. Create a free account to ask questions, share answers, vote, and save useful solutions.