mapbox / mapbox/turf-swift

Feature should conform to Identifiable

Open
#165 1 comment 0 reactions 0 assignees View on GitHub
jira-sync-complete op-ex question
Dominant language
Swift
Stars
271
Forks
65
PR merge metrics
No merged PRs in 30d

Description

The Swift standard library defines an `Identifiable` protocol that provides for an `id` property. The documentation for this property says the ID’s value can be as unique or as commonplace as the containing type defines it to be. That would make it well-suited for the `id` property on Feature objects in GeoJSON.

Turf currently stores this property in `Feature.identifier`. Perhaps we should rename `identifier` to `id` and have `Feature` conform to `Identifiable`. This would make the identifier more discoverable. However, GeoJSON feature IDs are optional, so the `ID` associated type would need to be `Optional`, which is probably not what most `Identifiable` consumers would expect.

The name `identifier` follows the [Cocoa naming convention](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE) that abbreviations such as “ID” should always be spelled out. To my knowledge, the Cocoa convention was motivated by the need to avoid collisions with the Objective-C keyword `id` and the awkwardness of a property named `ID`, capitalized according to another Cocoa convention. These considerations are less relevant to Turf, which has never supported Objective-C. The Swift naming guidelines make an exception for “[embracing precedent](https://swift.org/documentation/api-design-guidelines/#embrace-precedent)”, and there’s plenty of precedent for “ID”.

To maintain backwards compatibility, we could retain the `identifier` property as a deprecated computed property based on `id`. It’s unclear if the `Identifiable` conformance would be a backwards-incompatible change, but we could probably get away with it because `Identifiable` is still seldom used at this point.

/cc @mapbox/navigation-ios @mapbox/maps-ios

Contributor guide

Open the contributing guide

Research direction

Start by locating the Swift Feature type and its identifier property, then review how its public API and GeoJSON IDs are represented. Check Swift Identifiable requirements and the repository’s compatibility expectations; done means the naming, optional ID behavior, conformance, and deprecated compatibility path are resolved and covered by relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
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.