mapbox / mapbox/mapbox-maps-ios
Proposal: `Annotation.userInfo` should be non-optional
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
The current Annotation protocol defines userInfo as [String: Any]?
This can encourage some subtle bugs:
struct Polyline {
var userInfo: [String: Any]?
}
// Assigning to nil
var foo = Polyline()
foo.userInfo?["test"] = 1
print(foo.userInfo ?? "Missing") // "Missing"
// Easiest solution
foo.userInfo = ["initial": "value"]
foo.userInfo = ["test": 1] // This will override any existing values
print(foo.userInfo ?? "Missing") // "["test": 1]" The initial value is missing
// More correct solution
foo.userInfo = foo.userInfo ?? [:]
foo.userInfo?["new"] = "value"
print(foo.userInfo ?? "Missing") // "["test": 1, "new": "value]"
Making userInfo non-optional would not entirely remove the possibility of bugs, but it would reduce the likelihood and make code much simpler.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Annotation protocol declaration in Sources/MapboxMaps/Annotations/AnnotationOrchestrator.swift at line 13, then trace the affected Annotation conformers. Determine the required API and implementation changes so userInfo is non-optional; the issue is complete when annotations can update userInfo without optional initialization or replacement pitfalls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100