mapbox / mapbox/mapbox-maps-ios

Proposal: `Annotation.userInfo` should be non-optional

Open
#962 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged feature :green_apple: v11
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.