Uploaded image for project: 'Swift'
  1. Swift
  2. SR-13962

Interface builder ignores SupportedPlatforms value for Swift packages with IBDesignables

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Package Manager
    • Labels:
      None
    • Environment:

      Xcode 12.2 (12B45b) / Xcode 12.3 RC (12C33)

      macOS 11.0.1 (20B50)

       

      Description

      When using an IBDesignable component from an SPM package as a custom class in an interface builder document, it is being built for platforms other than the ones specified in the package description to render the designables. This only occurs when the IBDesignable is inside an SPM package.

      To reproduce the issue:

      1. Create a new swift package with the following package description (note the value for platforms).

      // swift-tools-version:5.3
      
      import PackageDescription
      
      let package = Package(
       name: "SPMDesignablePackage",
       platforms: [
       .iOS(.v12)
       ],
       products: [
       .library(
       name: "SPMDesignablePackage",
       targets: ["SPMDesignablePackage"]),
       ],
       targets: [
       .target(name: "SPMDesignablePackage"),
       ]
      )
      

      2. Create a single source file SPMDesignableControl.swift in the Sources directory of this package.

      import UIKit
      
      @IBDesignable
      public class SPMDesignableControl: UIView {
       
       @IBInspectable public var designableColorProperty: UIColor = .blue
       
       public override func prepareForInterfaceBuilder() {
       super.prepareForInterfaceBuilder()
       backgroundColor = designableColorProperty
       }
      }
      

      3. Create a new Xcode project and drag this new package to the Project Navigator.
      4. Add this package as a dependency in the Frameworks, Libraries, and Embedded Content section of the build target.
      5. In Main.storyboard, add a UIView and set this view's Custom Class to SPMDesignableControl in the Identity Inspector.
      6. Click on Editor > Refresh All Views to force the designables to render.
      7. The Identity Inspector for SPMDesignableControl will show a build error, with a message expecting the existence of a tvOS product/target.

      My expectation is since iOS is the only explicitly specified platform in the package description, it should not attempt to build the package sources for tvOS (or other platforms).

      I've also seen multiple threads describing a similar issue with no solution:
      https://developer.apple.com/forums/thread/652552
      https://developer.apple.com/forums/thread/652558
      https://developer.apple.com/forums/thread/661391
      https://stackoverflow.com/questions/64881772/

      A zip archive is attached below containing the SPM package (SPMDesignablePackage) and sample project setup (SPMDesignablePackageUser).

        Attachments

        1. error.png
          error.png
          142 kB
        2. SPMDesignableBug.zip
          60 kB

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            nico.elayda Dominic Elayda
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: