Skip to content

Bundle.urls(forResourcesWithExtension:subdirectory:) returns [NSURL] on Linux instead of [URL] #5446

Description

@maartene

Describe the bug
On Linux, Bundle.urls(forResourcesWithExtension:subdirectory:) returns [NSURL]? instead of [URL]?. This causes a cascade of type errors when iterating the result, because NSURL properties (path, lastPathComponent, pathExtension) are String? rather than String, and methods like deletingPathExtension() and path(percentEncoded:) from the Swift URL type are unavailable.

The singular variant Bundle.url(forResource:withExtension:) returns URL? consistently on both platforms and is unaffected.

To Reproduce
Create a new Swift package and add to main.swift:

import Foundation

let urls = Bundle.module.urls(forResourcesWithExtension: "png", subdirectory: nil) ?? []

for url in urls {
    // Linux: url is NSURL — these all fail to compile:
    let key = url.deletingPathExtension().lastPathComponent 
    let path = url.path(percentEncoded: false)
    let ext = url.pathExtension

    // ^^^ compile fine on macOS
}

Expected behavior
Independent of platform, Bundle.module.urls(forResourcesWithExtension: "png", subdirectory: nil) ?? [] returns an array of URL (Array<URL>)

Configuration (please complete the following information):

  • Swift Version: Swift 6.3
  • OS: latest macOS, Ubuntu 24.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions