Having trouble with adding a Swift package to MacOS 12.X+ - swift

I am writing my first MacOS App from the helloworld starter app. I want to eventually write swift code that calls a thrift server running on the same machine.. but this libraries instructions simply state to modify a file I don't seem to have.
Are these instructions only applicable to iOS ?
### Installing
#### Swift Package Manager
Add the following to your Package.swift file
.package(name: "TwitterApacheThrift", url: "https://github.com/twitter/ios-twitter-apache-thrift", .upToNextMajor(from: "1.0.0"))
#### Carthage
Add the following to your Cartfile
github "twitter/ios-twitter-apache-thrift"
Source : https://github.com/twitter/ios-twitter-apache-thrift
MY Screenshot of my files
I tried the add package dialog with the URL but got an error

You are not adding correct URL. It needs to be "https://github.com/twitter/ios-twitter-apache-thrift.git" instead of "https://github.com/twitter/ios-twitter-apache-thrift" . Means you need to add .git suffix. Also the instruction for installing that you posted
is meant for integrating thrift Package into another package as package dependency. If you just need to integrate the thrift package into your project, use the correct URL that I provided with standard way of adding package, as you tried before.

Related

Flutter IOS Duplicate plugin key: SocialSharePlugin

I am using two different share plugins in my flutter project. One plugin social_share_plugin and other is social_share . Both are used to share content on social media. Due to limitation of one plugin i have to use both. But i am getting 'Duplicate plugin key: SocialSharePlugin'error when i run the project on IOS device. it is working fine on android device.
var s = await SocialSharePlugin.shareToFeedFacebookLink(
quote: 'Meeting',
url: shareLink,
);
and other plugin is used like
await SocialShare.shareTwitter(
shareText,
hashtags: ["meetup"],
url: shareLink,
trailingText: '#meeting',
);
The issue is social_share uses the same class name as social_share_plugin (they both have SocialSharePlugin). To resolve this, I forked the social_share package and changed every instance of SocialSharePlugin to SocialShare, including the file names.
Here's my forked repo if you would like to use or view: https://github.com/kaarens93/social_share
(I have a lot of 'unresolved reference' errors that I'm still in the process of fixing but unless you want to build the package, you shouldn't run into any issues implementing into your project)
I ended up remove SocialShare completely from the project, and use flutter_share_me and SocialSharePlugin. I found Social_Share_plugin is the only one that works with Ins (and Facebook). None of the other packages worked in this aspect. However, with version 0.4 of SocialSharePlugin you need add Facebook api token to your info.plist file since the FBSDK used by SocialSharePlugin requires this token since version 13+. This change was not documented by 0.4 SocialSharePlugin.

How do I use Swift Package Manager with an existing macOS project?

I've been using Cocoapods to manage dependencies for my Swift project. I came across this package which is not listed at Cocoapods. Instead it suggests using Swift Package Manager. However, whenever I try to use Swift Package Manager to do basically anything, it ends up completely destroying my entire project.
So, in order to figure out how to actually use Swift Package Manager, I'm playing with it in a test project.
Here's what I've tried:
Create a new project from Xcode
File -> New -> Project -> Cocoa App
Product Name: basic-ssh-test
This creates a basic application which loads a blank window when I hit "Run". Just for fun I added print("test") to the applicationDidFinishLaunching function in my AppDelegate so the debug window says "test" when I run the program.
Now I want to add the Shout package as a dependency.
swift package init --type executable
This creates the following files:
Creating executable package: basic-ssh-test
Creating Package.swift
Creating README.md
Creating .gitignore
Creating Sources/
Creating Sources/basic-ssh-test/main.swift
Creating Tests/
Now I'm going to add the "Shout" dependency to my new Package.swift file:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "basic-ssh-test",
dependencies: [
.package(url: "https://github.com/jakeheis/Shout", from: "0.2.0")
],
targets: [
.target(
name: "basic-ssh-test",
dependencies: ["Shout"]),
]
)
And I'll pull in the dependencies:
swift package resolve
This results in the dependencies being pulled into the .build directory:
Fetching https://github.com/jakeheis/Shout
Fetching https://github.com/jakeheis/CSSH
Fetching https://github.com/IBM-Swift/BlueSocket
Cloning https://github.com/IBM-Swift/BlueSocket
Resolving https://github.com/IBM-Swift/BlueSocket at 0.12.91
Cloning https://github.com/jakeheis/CSSH
Resolving https://github.com/jakeheis/CSSH at 1.0.3
Cloning https://github.com/jakeheis/Shout
Resolving https://github.com/jakeheis/Shout at 0.3.0
Now I regenerate the xcodeproj file:
swift package generate-xcodeproj
Now when I open the xcodeproj file there is a new group called Sources that has a single directory basic-ssh-test with a single swift file in it main.swift with print("Hello, world!").
The code that I'm actually interested in running is now in a blue folder called basic-ssh-test. All of the necessary files are still in there, but instead of running my application, Xcode is running the main.swift file. I can tell because the debug output is "Hello, world!" instead of "test".
I've read a couple of tutorials that claim that Swift Package Manager will move my source files and continue to build the same as before, but that's clearly not the case.
There's also no longer a "Main Interface" option in my Build Settings, so I can't select "MainMenu.xib" as my application starting point.
This is essentially the same thing that happens when I try to use Swift Project Manager with my existing project. It pulls in the dependencies, but it basically ignores my entire existing project and just runs the "hello world" code.
How do I use Swift Package Manager to add a dependency to an existing project without ignoring the existing codebase?
I think SPM is only compatible with Mac command line executables or libraries. This explicitly states SPM doesn't support iOS, watchOS, or tvOS platforms at all. But, since macOS AppKit/Cocoa application targets are very similar to iOS or tvOS Xcode targets, I would say this statement implies that SPM can't be used with macOS Cocoa applications out of the box either, which is what I think you're hoping for.
It looks like there is some work here on how to use it with iOS application targets which should largely translate to a macOS Cocoa target.
Until the time of this writing answer, Swift Package Manager do not support the iOS, tvOS, and watchOS. Instead, you will have to add the files from the package directly to your project.
I would suggest you creating a Dependencies group in your project and a group below that with the package name, like this answer:
So, first you will add the files dependency that you want to import into your project to the name of the package name that included in Dependencies group that we make before.
After you add the files then you can access the code as you usually would when you write it yourself like the image below. No need imports. You can see more details in here. hope it helps.
You can create a windowed application using SPM (I have a whole project sitting waiting for ABI that does this) you just need some boiler plate in swift.main. I’ll dig it out.
However the method others are suggesting is never going to work (with current versions of SPM).
However, what I am seeing is that you really want to use SPM to manage dependencies (keeping up to date etc). So I think you could do that much more easily.
Rather than creating a executable as your default target, instead create a library (perhaps call it basic-ssh-dependencies). Generate your Xcode project and drag THAT into your primary Xcode project and configure your target to to depend on it. When you update the library from SPM for changes in dependencies you should re-gen your Xcode-proj.
Let me know your mileage and any wrinkles, or if I’ve misunderstood what you are trying to achieve.
Update for XCode 11
This is A LOT easier now with XCode 11. As of this writing the current version of XCode is 11.3.1.
For an existing XCode project simply:
go to File->Swift Packages->Add Package Dependency...
enter the URL of the hosted package you want to add
choose the rules about which versions your app will use
click Finish

Embedding Frameworks from SwiftPM into Cocoa Application (XCODE)

I'm using a project called "HAP" (https://github.com/Bouke/HAP) that is built using SwiftPM.
The included example "HAP-server", works great from Command Line and I have used the params "swift package generate-xcodeproj" to create an XCODE project.
I can also load the HAP in XCODE and build/debug the target "HAP-server".
I'd like to use this framework in my Cocoa Application and have added the HAP.xcodeproj into my project. I added the produced files as "Embedded Binaries" and "Linked Frameworks and Libraries".
That allows me to "import HAP" into my view controller class.
However, when I try to build my Cocoa target, I get the following message -- seems related to the dependency "Kitura-net" from the HAP project...
"Missing required modules: 'CCurl', 'CHTTPParser'"
What is the best way to use frameworks from a SwiftPM in my project?
I assume it has something to do with Search headers... anyone have an idea?
UPDATE #1:
I have tried adding to my Cocoa Project that is importing the library that is using Kitura by "Link Binary With Libraries", libcurl.4.dylib from usr/lib/ but it still gives me the same error.
UPDATE #2:
UPDATE #3
I ended up figuring it out by using this method: Importing CommonCrypto in a Swift framework
I needed to create a modulemap for each of the items it was throwing a fit about, in my case: CCURL & CHTTPParser. Once I did that, I could compile.
You can see an example of embedding Kitura in an Xcode project in this repo https://github.com/IBM-Swift/Kitura-HelloWorld-iOS. Makefile in this repo runs build scripts to fix an Xcode Project to run Kitura on iOS. You need to compile curl for iOS - see instructions in the README.
From what I remember, you need to add the directory with curl headers to Header Search Paths, the directory with libcurl.a to Library Search Paths, and also add -lz flag to Other Linker Flags.

install titanium module from github

i'm having some issues getting modules to work on my app - I keep on getting told that the requested module cannot be found.
It is entirely possible that i'm not installing the modules correctly - so, for the purposes of this question:
Once i've downloaded the zip file from git hub using the green "download" button, what do i do to import the module into my project? Not how do i tell tiapp.xml to use the module - just what do i do to install it?
Can you please run through using the facebook module found at https://github.com/appcelerator-modules/ti.facebook
thanks!
Inside the zip file of the download you'll see there is a folder called modules. This is the same folder that is in your root of the project.
So, an iOS module should be installed in the /modules/iphone folder. Once added, you can add Facebook to your app like this:
<module platform="iphone">facebook</module>
If you want to specify a version you can do so like this:
<module platform="iphone" version="1.1.0>facebook</module>
note: I made up the version number
You can also add it through the tiapp editor in Appcelerator studio, although it doesn't always seem to find the module. This might be a bug in studio though, usually it works great.
HMMMM
Two main issues here, one directly relating, the other less so.
Issue 1
The link i gave to get the codebase from github is wrong - well, it gets the codebase, but not in a form that can be used as a module. It is, in fact, the uncompiled version.
Versions for download can be found here.
So that takes care of issue one, what about
Issue 2
The latest version for use is a bit broken. Seems someone (from the appcelerator team???) decided to make the latest 6.0.1 release have a minsdk of the (at this time) as-yet-unreleased version 6.0.0, and sets the apiversion to 3.
This breaks the current release of 5.5.1, so for anyone reading this prior to 6.0.0 for appcelerator, you will want to use this release version.

CocoaPods framework with dependencies - include of non-modular header inside framework module

I am trying to build a private CocoaPods framework with other pod dependencies.
Among others, I added Parse as a dependency in the podspec file:
s.dependency 'Parse'
However, when I try to lint it,
pod lib lint MyPrivateSpec.podspec --verbose --sources 'git#bitbucket.org:MY_BITBUCKET_NAME/specs.git,https://github.com/CocoaPods/Specs'
I get the following errors:
Target Support Files/Parse/Parse-umbrella.h:3:9: note: in file included from Target Support Files/Parse/Parse-umbrella.h:3:
ERROR | xcodebuild: Parse/Parse/Parse.h:12:9: error: include of non-modular header inside framework module 'Parse.Parse'
[and more of these types of errors in the following lines ...]
I looked at virtually every relevant question asked on SO and in github issues, but I could not find anything that worked for me. Has anybody experienced these issues, or is familiar with why this does not work ?
This is unfortunately a problem with the Parse library itself. I ran into a similar situation a while back when I was trying to use the Parse library inside a framework I was building for iOS.
What the error means is that there is a header included in one of Parse's public .h files that does not belong to a module. In Parse's case this is <sqlite3.h> if I remember correctly. Without removing this from Parse's public headers it will not be possible to build a framework target that also includes Parse. This should be filed as a bug with Parse so they could work on an upgrade to support modular framework builds.
Due to the need for my project to build a framework target I had to pass on using Parse in my project as a result of the above.
Here is a reference to a similar problem with similar answer: https://stackoverflow.com/a/24728646/296708