Search code examples
swiftxcodelocalizationswift-package-managerlocalizable.strings

Swift Package manifest property 'defaultLocalization' not set


Experimenting with Swift Packages, I created a new package. Source files and resources from an existing Xcode project framework target were moved over into the new structure.

Attempting to build, the transcript shows an error:

manifest property 'defaultLocalization' not set; it is required in the presence of localized resources

How can this be solved so I can create a Swift package?


Solution

  • This is explained in WWDC2020 session 10169.

    At around eleven and a half minutes into the video, Anders Bertelrud, Apple engineer Developer Tools introduces the topic. An example is shown using Xcode 12 to add a default localisation parameter to the package manifest.

    This declares the language I'm using during development and will be used as the fallback localization at runtime if no better match is available. This is needed for any package that contains resources.

    An example manifest including the defaultLocalization parameter can be seen as follows:

    // swift-tools-version:5.3
    // The swift-tools-version declares the minimum version of Swift required to build this package.
    
    import PackageDescription
    
    let package = Package(
        name: "MyPackageUI",
        defaultLocalization: "en",
        platforms: [
            .iOS(.v13)
        ],
        products: [
            .library(
                name: "MyPackageUI",
                targets: ["MyPackageUI"]),
        ],
        targets: [
            .target(
                name: "MyPackageUI",
                dependencies: []),
            .testTarget(
                name: "MyPackageUITests",
                dependencies: ["MyPackageUI"]),
       ]
    )