• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Is this really the proper way to check the count of an optional string in Swift?

Resolved: Is this really the proper way to check the count of an optional string in Swift?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am scrolling through an array of many things in app. One of the items in the array is a string, and it is an optional. I’ve edited out everything else since my question is about the strings.
At one point I need to call some functions on the strings, if they exist.
Both of these appear to work
and
The top one is cleaner, but I can read the second one easier. The first looks like a cousin of a ternary conditional. I simply want to clarify that even if I am doing it correctly, if there is a more accepted way to do it.

Answer:

Comparing a default against a number is code stink. Deodorizing usually involves Optional.map
or better usage of properties.

If you have better answer, please add a comment about this, thank you!

if-statement swift
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Is pandas groupby() function always produce a DataFrame with the same order respect to the column we group by?

24/03/2023

Resolved: Kivy widget hierarchy not behaving as expected

24/03/2023

Resolved: Pandas Groupby Get Values from Previous Group

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.