why not work in swift markersShown.text = "Showing " + markers.count
- User
why not work in swift
markersShown.text = "Showing " + markers.count
- Assistant
The reason your Swift code line
markersShown.text = "Showing " + markers.countmay not be working could be due to a type mismatch issue. In Swift, you cannot concatenate aStringwith anIntdirectly using the+operator, which seems to be what you're attempting ifmarkers.countis an integer, which it usually is as a count of items in a collection such as an array.To correctly concatenate a string with the count of markers, you need to convert the integer to a string first. You can do this using string interpolation as follows:
markersShown.text = "Showing \(markers.count)"In this example,
\(markers.count)will replace the count into the string wherever it is placed. String interpolation can be used to insert a string representation of any type into a string.Alternatively, you can convert the integer to a string explicitly:
markersShown.text = "Showing " + String(markers.count)Remember also to ensure that
markersShownis an appropriate IBOutlet for a UILabel or similar UI element that is correctly linked to your storyboard or UI code, and that is accessible in the context where you're trying to set the text. Otherwise, you might face other issues related to unwrapped values or runtime exceptions.