问题描述
在使用Swift Package Manager时,我需要在测试目标之间共享一些代码。为此,我有一个.testTarget,我也将其命名为另一个.testTarget的依赖项。
这是一个简单的例子:
// 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: "ExampleLib",products: [
// Products define the executables and libraries a package produces,and make them visible to other packages.
.library(
name: "ExampleLib",targets: ["ExampleLib"]),],dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */,from: "1.0.0"),targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package,and on products in packages this package depends on.
.target(
name: "ExampleLib",dependencies: []),.testTarget(
name: "Common",dependencies: ["ExampleLib"]),.testTarget(
name: "ExampleLibTests",dependencies: ["Common"]),]
)
如果我尝试在Xcode中构建此程序包,则会出现以下错误:
Unable to resolve build file: XCBCore.BuildFile (The workspace has a reference to a missing target with GUID 'PACKAGE-TARGET:Common')
但是,如果我从命令行(swift build
)进行构建或从命令行(swift test
)进行测试,则可以成功。
我正在使用Xcode 12 beta 6,但也尝试过Xcode 11.5(对Package.swift标头进行了更改),并获得了相同的结果。
这是完整的Swift软件包示例: https://www.dropbox.com/s/h6ypvbfonnb2zyk/ExampleLib.zip?dl=0
我真的很想在Xcode中使用它来构建iOS版本。有想法吗?
解决方法
我遇到了同样的问题,并通过为 <controls:FlowListView x:Name="PhotoFlowListView"
SelectedItem="{Binding SelectedPhoto,Mode=TwoWay}"
FlowColumnCount="3"
HorizontalOptions="StartAndExpand"
SeparatorVisibility="Default"
RowHeight="160"
FlowItemsSource="{Binding Photos}"
SelectionMode="Single">
<controls:FlowListView.Behaviors>
<behaviors:EventToCommandBehavior EventName="ItemTapped"
Command="{Binding PhotoSelectedCommand}"
EventArgsConverter="{StaticResource LocalItemTappedConverter}">
</behaviors:EventToCommandBehavior>
</controls:FlowListView.Behaviors>
<controls:FlowListView.FlowColumnTemplate>
<DataTemplate>
<StackLayout Padding="3">
<ImageButton
Source="{Binding PhotoUrl}"
Style="{StaticResource PhotoStyle}"
VerticalOptions="FillAndExpand">
</ImageButton>
</StackLayout>
</DataTemplate>
</controls:FlowListView.FlowColumnTemplate>
</controls:FlowListView>
定义了一个 Target (不是Test Target)来解决了这个问题。
我的Common
文件:
Package.swift