I have a small Swift library intended to import a c library for use in Swift.
I'd like to use that in a "hello world" Mac app I have built in Xcode. This seems like a very simple use-case, but I have not been able to figure out specific steps will let me include that swift library -- add to targets? import the library project into xcode? build as a framework and add? This feels very elementary, but I can't find an up-to-date how-to for Swift 5 and Xcode 10.2.
Related
In iOS, React Native support CocoaPods for Objective-C and Swift code.
Is there any way to bring 3rd party libraries via Swift Package Manager?
You can perfectly add SPM to iOS project inside your React Native solution.
Treat it as a common iOS dependency.
You can present any viewControllers from rootViewController
I'm developing a framework in swift targeting iOS devices. The usual pipeline include add a playground to the framework in order to test some functionalities. However, since the last update to macOS Mojave I always get messages like
No such module 'FrameWorkName'
I tried some solutions that I found on the internet, like create a workspace and add the framework and the playground, but even then it's not working. Keep in mind that the exactly same piece of code ran flawlessly on the previous OS.
How do I add custom frameworks to swift playgrounds in macOS Mojave with Xcode 10? Also, is there a better way to test custom frameworks? I understand that the swift playgrounds are trying to mimic the Jupiter-notebook style of coding, and that is awesome, but it stills need some improvement.
3rd party frameworks can’t simply be included in a playground
There is a way to solve it. It is well described in Paul Ardeleanu's post on Medium
I am currently building code that I would really like to use as a framework by being able to import MyCustomFramework as I would with Apple frameworks (in the future I would also like to distribute them).
I have some questions about that :
What is the easiest way to build a framework as what I want? Is this possible to do it directly in Xcode or do I need to use command line tools in the Terminal?
Will this framework be compatible with multiple platforms (I am thinking about all Apple platforms but also about other platforms supported by Swift such as Linux).
What is exactly the link between Swift frameworks and the Swift Package Manager ? Do I need SPM to build my framework or is this two different tools?
Thank you.
Currently, Swift Package Manager (SPM) and Xcode Frameworks follow different paths. For Linux, you have to follow the SPM path since the only way to compile a Linux swift application is to use SPM. For macOS command line apps, you can follow the SPM path as well. For iOS apps and macOS UI apps, you have to follow the Xcode Frameworks path.
For the SPM path, you make the project of your framework SPM-enabled: add Package.swift file and set the file layout of your project according to SPM conventions. The project also has to be a git repository. Then the git repository of your project can be specified as a dependency to other SPM-enabled frameworks/applications. Each SPM-enabled project can be converted to an Xcode project any time by using swift package generate-xcodeproj command.
The Xcode Frameworks path is the standard, pre-SPM way of working with frameworks with Xcode, which is described elsewhere. You create an Xcode Project that will define your framework.
So, if you want your framework to be used both in SPM-enabled projects for Linux and macOS command line apps, and in Xcode-enabled projects for iOS and macOS UI apps, you have to follow the dual path. You make your project SPM-enabled and add an Xcode Project which will define your framework. You will have to maintain your project information twice - in Package.swift file and in the Xcode Project.
I gave a detailed answer on how to use Xcode to create a Framework target in an answer 2 weeks ago here. The question wasn't specifically related to Frameworks, so I can understand how it doesn't come up in a search. (I also believe if I copied/pasted it here that would be unwelcome, but if I'm wrong I'll do it.)
For now a Swift Framework target can be compatible across Apple platforms, provided you separate UIKit, Foundation, and core code into their own frameworks. (There may be a better way but that's the best way I know.
About Swift core code: Currently Swift is (still) evolving fast. Swift 3 is beginning to have production server-side use and some Linux use, but right now with no binary compatibility (that's part of Swift 4) I'd stick to Apple platforms.
I've heard conflicting things about Swift version compatibility between Swift 2 & 3. By this I mean you can use both in the same project, but there are hurdles if you do.
I have a bunch of code in an iOS project (named "MyLibs") I re-use across different apps. I drag the MyLibs project into the workspace of whatever app I'm creating. I don't use unit tests per se, but I have buttons than run through all the tests very easily in the iPhone app.
I'm learning Cocoa and would like to divide up my library into libs I can use on both projects. I was thinking it would be MyCommonLibs (or MyFoundationLibs), MyIOSLibs and MyCocoaLibs.
However, when creating a new project, I must choose between an iOS app or a Cocoa app. It looks as though the iOS Framework and Library -> Cocoa Touch Static Library is appropriate because it links against the Foundation framework. On the other hand, I'd prefer to use an application template if there is no major drawbacks to it.
I need to be able to use MyCommonLibs in both app types, as some of them are useful to both, such as NSArray categories, etc.
Which template should I use for the MyCommonLibs and must I use a Library, Framework (in the Mac OS templates) or can I just use a normal application template (as I've been doing thus far)?
Create an iOS Framework & Library project. Let's call it TestLib.
Add a new target (File > New > Target) of type MAC OS X Framework & Library.
This way, you can compile both an iOS library and a MAC OS X library from the same project.
You can choose which files are included in each target. So if you want to make a class available for both iOS and MAC OS X, you add it to both, and if you want to make it available for only one platform, you can add it to only one lib.
As you can see in the screenshots below, SharedClass is available in both libs, iOSOnlyClass is available for iOS only and MACOnlyClass is available for MAC OS X only.
You can also add targets for unit tests in the same project.
To organize your code, you can put the shared classes in a group, and the classes of each target in a separate group.
I have my drupal xml-rpc service setup, and now I want to retrieve content for my iphone app.
I'm attempting to use https://github.com/eczarny/xmlrpc, however I dont know where to begin. How do I add the project to my own project for use? I've added a static library before; is it the same process? Just drag the proj file to my project and add the xml-rpc library?
Any tips would be appreciated.
Try dragging the project file for xmlrpc framework into the code list in XCode for starters. Next make the framework target in the xmlrpc framework a build dependency. Finally add the xmlrpc.framework to your linked frameworks. Exactly how you do this depends on whether you are using XCode 3 or 4