mapbox / mapbox/mapbox-maps-ios

ViewAnnotationManager.annotations fails to compile under Xcode 16.1 (Swift 5.10+) due to generics inference; explicit dictionary build fixes it

Open
#2,378 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
Dominant language
Swift
Stars
601
Forks
196
PR merge metrics
No merged PRs in 30d

Description

## Environment
- Xcode: 16.1
- iOS deployment target: 15.1
- Build target: iOS Simulator (Debug; also reproducible on device builds)
- React Native stack (for context):
- Expo SDK: 54.0.22
- React Native: 0.82.1
- React: 19.2.0
- Hermes: enabled
- @rnmapbox/maps: 10.2.6

## Platform
- Platform: iOS
- Language: Swift
- Build system: CocoaPods + xcodebuild (React Native / Expo integration)

## SDK versions
- Mapbox Maps iOS: 10.17.0 (via CocoaPods, transitive dependency from @rnmapbox/maps 10.2.6)
- MapboxCoreMaps: 10.17.0
- MapboxCommon: 23.9.2
- MapboxMobileEvents: 1.0.10
- Turf: 2.7.0

## Observed behavior and steps to reproduce

Building a project that includes MapboxMaps 10.17.0 fails on Xcode 16.1 with a Swift type mismatch originating in ViewAnnotationManager.swift. The compiler infers a dictionary of type [UIView: ViewAnnotationOptions] where the code expects [String: Any?], causing a hard compile error.

Replacing the computed property that uses a compactMap/transform chain with an explicit dictionary construction (with explicit types) resolves the issue without changing behavior.

## Steps to reproduce
1. In a fresh iOS project (or React Native/Expo iOS app) add @rnmapbox/maps 10.2.6, which installs MapboxMaps 10.17.0 via CocoaPods.
2. pod install
3. Build with Xcode 16.1 or via xcodebuild for iOS Simulator (Debug or Release).

## Expected behavior

The project compiles successfully.

## Notes / preliminary analysis

## Actual behavior
Compilation fails in MapboxMaps with a type mismatch error.

## Error logs
```
Pods/MapboxMaps/Sources/MapboxMaps/Annotations/ViewAnnotationManager.swift:67:XX: error: cannot convert return expression of type '[UIView : ViewAnnotationOptions]' to return type '[String : Any?]'
```

Notes:
- The error points at the computed property that constructs a dictionary using a compactMap/values transform.
- Under Xcode 16.1, Swift’s inference appears to resolve the dictionary as keyed by UIView with ViewAnnotationOptions values, conflicting with the function’s expected [String: Any?] return type.

## Minimal code location
- File: Pods/MapboxMaps/Sources/MapboxMaps/Annotations/ViewAnnotationManager.swift
- Symbol: computed property building “annotations” for view annotations (uses a compactMap/values transformation)

## Workaround (verified)
Implement the dictionary with explicit construction and types (avoid the compactMap/values chain). For example, conceptually:

```swift
// Before (approximate shape)
private var annotations: [String: Any?] {
// builds a dictionary via compactMap/values chain
}

// After (works on Xcode 16.1)
private var annotations: [String: Any?] {
var result: [String: Any?] = [:]
// explicitly iterate and insert with the desired key/value types
// (no behavior change; avoids inference mismatch)
return result
}
```

Applying this change locally in the Pod source restores successful builds on Xcode 16.1.

## Additional context
- The failure started when building with Xcode 16.1; earlier Xcode versions may not hit the same inference path.
- Our environment uses the prebuilt RN 0.82/Hermes toolchain. The issue appears isolated to Swift type inference in MapboxMaps rather than React Native integration.
- We confirmed the workaround by patching the Pod file post-install; the app builds and runs with Mapbox normally afterward.
## Additional links and references

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 in Pods/MapboxMaps/Sources/MapboxMaps/Annotations/ViewAnnotationManager.swift at the computed property that builds annotations. Reproduce the failure with Xcode 16.1 or xcodebuild, then inspect the compactMap/values transformation and the documented explicit dictionary workaround. Done means the project compiles successfully without changing annotation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
mobile-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.