要排除文件的整个部分,我可以使用宏来定位平台,例如const mongoose = require("mongoose");
const PostSchema = mongoose.Schema({
title: {type: String, required: true},
description: {type: String, required: true},
date: {type: Date, default: Date.now}
})
module.exports = mongoose.model('Posts', PostSchema);
。
在#if os(iOS) || os(watchOS)
中有没有办法做到这一点,还是在Swift Package Manager中为特定平台的一些文件提供了目标?
答案 0 :(得分:1)
在
Package.swift
中有没有办法做到这一点??
#if os(macOS)
和其他快捷内容也可以在Package.swift
中使用,因为程序包声明文件本身就是.swift
文件。
在GitHub搜索“ endif PackageDescription swiftLanguageVersions filename:Package.swift language:Swift”中可以找到一些示例,例如:
Package.swift
import PackageDescription
let package = Package(
name: "Quick",
products: [
.library(name: "Quick", targets: ["Quick"]),
],
dependencies: [
.package(url: "https://github.com/Quick/Nimble.git", from: "8.0.0"),
],
targets: {
var targets: [Target] = [
.testTarget(
name: "QuickTests",
dependencies: [ "Quick", "Nimble" ],
exclude: [
"QuickAfterSuiteTests/AfterSuiteTests+ObjC.m",
"QuickFocusedTests/FocusedTests+ObjC.m",
"QuickTests/FunctionalTests/ObjC",
"QuickTests/Helpers/QCKSpecRunner.h",
"QuickTests/Helpers/QCKSpecRunner.m",
"QuickTests/Helpers/QuickTestsBridgingHeader.h",
"QuickTests/QuickConfigurationTests.m",
]
),
]
#if os(macOS)
targets.append(contentsOf: [
.target(name: "QuickSpecBase", dependencies: []),
.target(name: "Quick", dependencies: [ "QuickSpecBase" ]),
])
#else
targets.append(contentsOf: [
.target(name: "Quick", dependencies: []),
])
#endif
return targets
}(),
swiftLanguageVersions: [.v4_2]
)