Failed to Display Image in Swift Package Manager XCAssets using UIKit - swift

I'm currently working on Swift Package Manager project and I need to use images (myImage) I put in my custom XCAssets (CoreUI.xcassets). I have included my XCAssets in the SPM resources like this.
targets: [
.target(
name: "MyCoreUI",
dependencies: [],
resources: [Resource.process("Resources/CoreUI.xcassets")]),
.testTarget(
name: "MyCoreUITests",
dependencies: ["MyCoreUI"]),
]
I accessed my image like this:
UIImage(named: "dropdown_down", in: Bundle.module, compatibleWith: nil)
But my image still failed to load without any warning. Could anyone help me with this issue? Thank you in advance!

Related

Swift Package Manager: how do I archive?

I have created a Swift Package via Xcode. This packaged defines a library:
let package = Package(
name: "SPMBasedA",
products: [
.library(
name: "SPMBasedA",
type: .static,
targets: ["SPMBasedA"]),
],
targets: [
.target(name: "SPMBasedA")
]
)
The scheme is well displayed in Xcode and project seems to compile properly, but whenever I archive, there are no products in the exported archive. Why is that, what am I doing wrong? How do I make the build artifacts appear? Is it related to SKIP_INSTALL? If so, how do I disable it in SPM?

Swift Package Manager Problem With Bundle IDs

I'm pretty sure that SPM has the ability to fix this issue, but I am having a hard time finding it. I am quite sure that "I'm not holding it right."
I'm quite new to SPM, and am still struggling with its syntax and methodology.
Maybe all that needs to happen, is for someone to direct me to the appropriate PackageDescription docs (which I can't seem to find).
I am in the process of switching an app I developed over to use SPM for a few libraries that I also wrote. It has been using Carthage, and the libraries were added as simple source files (they are all single-source-file dependencies).
Everything works great...except that I get an App Store Upload rejection.
It does not like the bundle IDs for the embedded libraries. They have underscores in the project name, and I should replace those with dashes.
These libraries (this one, this one, and this one), are not really designed to be delivered as libraries. They are really single source files. It looks like SPM builds them into a library, but I don't really provide an Info.plist for the build.
Can anyone give me any guidance over how I can control the bundle IDs, while leaving the module names the same?
For the record, here are the errors I get:
OK. I figured it out.
First, the docs for SPM...leave something to be desired. I had to find this out by trial-and-error (LOTS of error).
In the Package.swift file, I had this (for one of my dependencies):
// swift-tools-version:5.2
import PackageDescription
let package = Package(
name: "RVS_Generic_Swift_Toolbox",
products: [
.library(
name: "RVS_Generic_Swift_Toolbox",
type: .dynamic,
targets: ["RVS_Generic_Swift_Toolbox"]),
],
targets: [
.target(
name: "RVS_Generic_Swift_Toolbox",
path: "./src")
]
)
Apparently, SPM uses the .library.name property as the BundleID. If I changed it, like so:
// swift-tools-version:5.2
import PackageDescription
let package = Package(
name: "RVS_Generic_Swift_Toolbox",
products: [
.library(
name: "RVS-Generic-Swift-Toolbox",
type: .dynamic,
targets: ["RVS_Generic_Swift_Toolbox"]),
],
targets: [
.target(
name: "RVS_Generic_Swift_Toolbox",
path: "./src")
]
)
Then, it would allow the upload, and I would still be able to do the import RVS_Generic_Swift_Toolbox.
Also, there's a bad cache issue. I had to delete EVERYTHING to make sure that the proper version was loaded.

/src: error: could not find source files for target(s): MyKituraAppTests; use the 'path' property in the Swift 4 manifest to set a custom target path

I'm trying to compile using swift build
Package.swift
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
// swift-tools-version:x.x
import PackageDescription
let package = Package(
name: "MyKituraApp",
dependencies: [
.package(url: "https://github.com/IBM-Swift/Kitura", from: "2.7.0")
],
targets: [
.target(
name: "MyKituraApp",
dependencies: ["Kitura"],
path: "Sources"),
.testTarget(
name: "MyKituraAppTests",
dependencies: ["MyKituraApp"],
path: "Test")
]
)
But, I get the following error although I did add the path property.
'MyKituraApp' /src: error: could not find source files for target(s): MyKituraAppTests; use the 'path' property in the Swift 4 manifest to set a custom target path
Without knowing your project structure I can't give you a definite answer but I'll do my best!
I'm going to assume you've generated your project using the Swift Package Manager tool, something like this:
swift package init --type executable
So... Typically you shouldn't need to set the path property unless you've moved the tests for your application to another directory. The Swift Package Manager, by default, will create a Tests directory and when you do not provide a value for the path property the Swift Package Manager will look for that Tests directory by default when you run swift build. In your path property you are providing a value of Test not Tests
So my first solution to test would be:
To remove the path property from the .testTarget section
OR
Rename the path properties value to Tests rather than Test.
I've provided an example Package.swift that I was able to run swift build with:
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyKituraApp",
dependencies: [
.package(url: "https://github.com/IBM-Swift/Kitura", from: "2.7.0")
],
targets: [
.target(
name: "MyKituraApp",
dependencies: ["Kitura"],
path: "Sources"),
.testTarget(
name: "MyKituraAppTests",
dependencies: ["MyKituraApp"])
]
)
As you can see I've also removed an extra line from the top of the file:
// swift-tools-version:x.x
You've already provided a swift-tools-version at the top of your file, this line may end up confusing things later down the line.
I hope this helps!

Cannot add SwiftCalendar as a dependency in vapor3 project via package manager

I am currently trying to add SwiftDate to a Vapor3 project via the swift package manager. Here is my package file:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "timeshare",
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
// Custom dependencies
.package(url: "https://github.com/malcommac/SwiftDate.git", from: "5.0.0"),
],
targets: [
.target(name: "App", dependencies: ["Vapor", "SwiftDate"]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App"]),
]
)
However, when I try to build my project I get 82 issues in Xcode (all from the SwiftCalendar module). For example this:
I have no idea how I can possible have caused errors in a third party library. Any input is highly appreciated.
Thanks
More errors can be seen here:
PS: Sorry for including screenshots, I know they might be hard to read, but I could not find a way to copy the error list as text.
The project isn’t in the correct format for SPM. All the files need to be declared in the correct target directory, but DateRepresentable is outside of that https://github.com/malcommac/SwiftDate/tree/master/Sources
It’s also worth noting that this doesn’t seem to have any tests on Linux and involves DateManipulation. I’d be very weary about using it since Dates on Linux are notoriously crashy

Using Alamofire in a command line OS X app (Xcode 7) - code encapsulation?

I'm trying to figure out how to use Alamofire in a command line app.
I can't use frameworks, so I've added the Alamofire source code into the app (so no import statement) and I'm able to directly reference the request() and other methods.
Is there a cleaner way to encapsulate Alamofire or is this a limitation in Swift 2.X at the moment?
For those who gonna need it here is the solution.
If you don't have the file xcodeproject please generate
$ swift package generate-xcodeproj
You may need to fix the Deployment Target
Now time to add the Alamofire
import PackageDescription
let package = Package(
name: "SuiteTest",
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0")
],
targets: [
.target(
name: "SuiteTest",
dependencies: ["Files", "Alamofire"]),
.testTarget(
name: "ASuiteTestTests",
dependencies: ["Assure-SuiteTest"]),
]
)
I hope I have helped anyone who has the same problem :)