I am trying to integrate ios-ntp into my project, which I develop using Xcode 7, swift 2.0 and cocoapods. I am adding the library as a pod. But when I try to add <ios-ntp/ios-ntp.h> to my app-BridigingHeader.h, Xcode doesn't recognize it. When I try to simply import the module and use it by #import ios_ntp ; Xcode complains that he is not able to build module 'ios_ntp'. Am I doing smth wrong?
upd. Actually Xcode is not able to build the module due to the error
'GCDAsyncUdpSocket.h' file not found
but that framework is present and added in 'ios-ntp' pod spec as dependent.
You shouldn't need to #import the library in your bridging header, Cocoapods should take care of making your pods available in Swift.
In your Swift files, have you tried import ios_ntp to import the library?
EDIT: Think I got it. Not 100% sure on why this is happening, but my hunch is that it's related to Cocoapods and ios-ntp's dependency on CocoaAsyncSocket. Something about ios-ntp's import of a CocoaAsyncSocket header is creating a circular dependency, which is borking ios-ntp's build.
Solution:
https://github.com/ruddct/ios-ntp should do the trick, that branch contains a few very minor header changes to forward declare the CocoaAsyncSocket stuff in ios-ntp's headers, which fixes the issue.
See How to prevent circular reference when Swift bridging header imports a file that imports Hopscotch-Swift.h itself for more background on this issue.
When you use Pods, you have to:
Open Pods.xcodeproj
In Targets select ios-ntp
Select 'Build Phases' tab
Add GCDAsyncSocket.h and GCDAsyncUDPSocket.h to Compile Sources and Headers
Remember to set 'Allow Non-modular includes in Framework Modules' to Yes in ios-ntp
For me, this works.
Related
I am attempting to import GoogleAPIClientForREST but Xcode is unable to find the module. I installed the following pods:
pod 'GoogleSignIn'
pod 'GoogleAPIClientForREST/Calendar'
GoogleSignIn is working and looks like all of the necessary files for GoogleAPIClientForREST were created in the project. In addition, I created a bridging header file with the following code:
#import "GTMAppAuth/GTMAppAuth.h"
#import "GTMSessionFetcher/GTMSessionFetcherLogging.h"
Not sure what I am doing wrong? I know others have run into this issue and I went through all of the provided solutions to no avail. I think I may need to add drag GTLR.framework to the project's Linked Frameworks source group, but am not sure how to do that nor if I actually need to given I installed GoogleAPIClient via cocoapods. I am using Xcode 12.4 and a laptop with the M1 chip if that makes a difference.
Thank you for the help!
Figured it out: needed to add: #import "GTLRCalendar.h" to my bridging file and did not need to add: import GoogleAPIClientForRest at the top of my files
EDIT: Getting negatives for such a detailed and HONEST question? Sometimes I don't really get Stack Overflow. Really.
Hi, I'm trying to create a PoC using Swift 5 (Xcode 10.2.1) and a modern rendition of ncurses (in this case, MacPorts' one, some 6.1.2018XXXX version)
My Poc has no code as of now, as my problems start before being able to add any sensible line to my .swift files.
So far I've done the following things:
1.- I have a proper working MacPorts ncurses library installed: that means "sudo port install htop" can build "htop" application without any problem, proving that way that my ncurses library is correctly installed (.h files seem to be deployed inside /opt/local/include/ directory)
2.- I create an empty CONSOLE APPLICATION swift program (using Xcode 10.2.1 own wizard). It just takes 4 mouse clicks, and you get some "Hello world" silly main.swift file.
3.- I create a bridging header to import my .h files (in this case ncurses.h).
The contents of this bridging header will/should be something like this:
#import "/opt/local/include/ncurses.h"
4.- I compile and run the silly empty "hello world" swift program, and I get tons of somewhat "expected" errors. Something like:
"Darwin/SDK curses.h symbol xxxxxxxxx is also defined inside your /opt/local/ncurses.h file. Bailing out." (it's not the literal error I get, you just get the idea)
So my question is:
Can I disable/remove Darwin/internal/MacOs SDK curses.h from my XCode project definition somewhere, in order my bridging header only sees one copy of my 2 (n)curses.h file (that should be my macports one)?
I've tried many things described in this other thread, but with no luck: How to disable "curses.h" header (a part of "stdio.h in Xcode 6.3 OSX Yosemite) to avoid conflicting function declarations
Specially "Enable Modules" option, which no matter the value you set it to, seems to do nothing.
BTW: I know when I might solve this .h headers issue, I will probably need to add some additional -lib linking option in the "build phase"(?) tab inside Xcode, but I'll try to manage myself when that moment arrives.
As of now my concern is "I wan't to remove Apple Internal Macos SDK curses support/files from my Xcode project". Is it achievable?
PS: I'm using Mojave 10.4.4 with no problem
I'm having the same issues, although trying to use ncurses via the Swift Package Manager. Despite being actively trying to find a solution I've been unsuccessful so far. Check my question just in case: Swift package manager unable to compile ncurses installed through Homebrew
This answer should give you all the information you need to get it working :) https://stackoverflow.com/a/56728436/554972
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
I am trying to add SQLite to my project.I checked the target dependencies under the build phase tab,it is empty, which is true.I am getting the following error:Unable to run command 'Ld SQLite' - this target might include its own product."
I am using swift 3.
Can you please help me? Thanks in advance
I'm not in front of a Mac at present, but I think all you need to do under Build Phases is go to Link Binaries with Libraries, hit the add button and type in "sqlite" so you can select libsqlite3.
Xcode 9 and Swift 3.2 (or, obviously Swift 4), just import SQLite3 in your relevant Swift file ...
import SQLite3
... and it will import the library for you.
In older Xcode versions (or if you turned off automatic library/framework linking), you have to manually link to the libsqlite3 library in the target settings under the “Build Phases”:
But in Xcode 9 with the default settings, all you need is that import line.
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.