Pretty new to creating frameworks with SPM dependencies. So I made a new framework project, added some of my classes/files as well as a SPM dependency (CocoaLumberjack logger). Framework compiles fine.
When I look for my framework product that I'm planning on embedding into some other project I see that it is in my Products folder. Alongside with it I see CocoaLumberjack module. Inside of my framework there is not much beside the exec file.
When I try to embed my framework into some other projects. Nothing compiles because it says that CocoaLumberjack module is missing.
Does anyone know how to fix this? Am I missing an important step or soemthing?
Well, there are numerous isses you could have faced during importing framework itself. It also depends if you use framework as binary or source code. I assume you were using source code approach as you are the creator of framework. You can however check all approaches here: in this SO question . Lets look at all the steps you need to implement in order to successfully use framework with SPM dependencies in your swift project.
create SPM properly and also link all additional SPM dependencies tutorial here. Make sure all your classes, structs etc. and their coresponding initializer has correct access level property. If you plan to use them outside of the package, use public initializers..
2)Once you created you SPM package, link it to framework. For the sake of this answer I created testFramework and linked one of my custom SPM package called VodApiPackage . This package also contains dependency to another BaseTvApiServicePackage.
I also added TestPrinter file containing simple function for creating error declared in my SPM package. This function servers only for checking that everything is working properly and will be user later. It is also declared public.
import Foundation
import VodApiPackage
public struct TestPrinter {
public init () {}
public func makeTest() {
let x = VodApiError.customErr(msg: "testMsg")
print(x.localizedDescription)
}
}
Open your project and make link to framework, you can also check this nice tutorial. The most important step from tutorial is step 5 and 6. Where you drag .xcproj into your project and link libraries and framework
make sure your library and SPM dependencies are correctly linked in your project. Check sample project below.
Build and test using your framework and its packages:
import UIKit
import testFramework
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
testmodel()
TestPrinter().makeTest()
}
}
Related
I'm trying to generate a swift framework which integrates 2 smaller frameworks developed in objective-c. The idea is to wrap them in order to be able to use them adding only the new framework in a Swift 5 project.
Can I generate it by only adding those 2 frameworks?
Maybe doing some Swift code which does some middle work?
I followed these steps:
1.- Created SDK project.
2.- Inserted both frameworks
3.- In the .h file, added imports to make them public.
4.- Added swift code configurating classes and function as public (most important step)
5.- When swift code was working, deleted in the .h file the imports in order to make both frameworks unaccesibles.
Hope this will help.
I need to create a framework in swift, that will internally use a static library. It would be great if this library was only visible internally in this framework. I have added all the files of this library to the framework, and I have created a module.modulemap file. This file looks like this:
framework module MySDK {
umbrella header "MySDK.h"
export *
}
module BluFi {
header "/Users/homedudycz/Documents/Developer/MyApp/MySDK/blufiprotocol/DH_AES.h"
export *
}
And I can now use objects from this static library inside my framework, but there is a problem. When I try to import my framework in some app I get an error: Missing required module 'BluFi'.
What am I doing wrong? Is there some other way to import this static library inside my framework internally?
I have also created a sample project with libraries that I need added in this SDK. Please take a look, and please update path in module.modulemap - I don't know how to make it relative to SDK path :/
https://www.dropbox.com/s/rnh7y7zr63zillv/TestApp.zip?dl=1
I created a library that uses the native navigation controller to navigate through react and native screens. The library is written in Swift and contains some objective-c code to setup the React bridge etc. Currently I can distribute this library through CocoaPods by creating a podspec and defining the React dependency there. However, this forces the user to setup React in their project through CocoaPods as well (like so: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html). I'd like them to use the react-native link or manually linking option as well (like so: https://medium.com/#joshyhargreaves/adding-react-native-to-existing-ios-project-without-cocoapods-6f1ee9106009).
If I understand correctly I can create a static library and distribute that. So far I created this static library, added my mixed swift and objective-c code and tried to manually link it into my main project. This however produces an error in one of my classes inside my static library where I import React like so import React. Error is "No such module 'React'.
I updated the Header Search Paths of my static library to contain:
$(SRCROOT)/../react-native/React
and
$(SRCROOT)/../React
(react-native, React and my own lib are all inside the node_modules folder)
both set to recursive. Unfortunately it still doesn't find the module React. Does anyone know how to create a static library that contains a dependency with React?
The end goal would be to import this static library in my main project like import MyStaticNaivationLib in one of my viewcontrollers and subclass from a class that's defined in my static library.
My main project also uses https://github.com/rebeccahughes/react-native-device-info. This looks exactly what I want to achieve. It's a static library that has a dependency with React ("import RCTBridgeModule.h") which I can manually link in my main project. Only difference is that this project doesn't contain Swift code.
I wrote a custom module for the company, and you can view my documentation. This custom module have inner framework and I link this framework to the main project. In your custom_modulem do you have package.json with this?
"peerDependencies": {
"react": "16.8.3",
"react-native": "0.59.4"
}
https://github.com/Hardy1207/RNOkay
I'm currently writing some swift libraries to be included in an App that uses CocoaLumberjack to log.
So initially I've added CocoaLumberjack as a dependency to all of them and it works quite well.
Then I've seen this ticket where they say, that you should not add it as a dependency, but use if it is there.
Despite that I've already seen some projects on GitHub where they do exactly that in Objective-C, I haven't seen it yet in Swift.
Can somebody point me to a sample project or help me to find the right direction to take
THX
Your should add CocoaLumberjack/Swift as a dependency if your library uses it as a logger.
But your library code should not add any loggers (DDTTYLogger, DDFileLogger, etc.) to avoid log duplication.
Adding loggers should be done in final application that uses your library.
For library itself it could be test bundle with tests:
class YourKitTests: XCTestCase {
override func setUp() {
super.setUp()
DDLog.add(DDTTYLogger.sharedInstance(), with: .verbose)
}
}
For example, I never use the description of XCTestCase.expectation, so I'd like to use a function to provide a default for it, and make it clear via naming that I'm initializing the expectation, as you can't really use an initializer for XCTestExpectation. But if the extension is not in a test target, then it can't compile:
Cannot load underlying module for 'XCTest'
import XCTest
public extension XCTestCase {
func makeExpectation() -> XCTestExpectation {
return expectation(withDescription: "")
}
}
I've created an xcworkspace here (https://github.com/dtweston/TestFrameworkSample) that demonstrates a solution to your issue. There are two projects in this workspace:
SampleApp project with an iOS app target and a unit test target.
SharedTestFramework project that imports XCTest and declares the single extension you put in your question.
The SampleAppTests target links to the SharedTestFramework to be able to use the extension it defines. The single test file imports the SharedTestFramework.
With those steps, I also encounter the Cannot load underlying module for 'XCTest' when building the SharedTestFramework.
The fix for that is to update the Framework Search Paths to include "$(PLATFORM_DIR)/Developer/Library/Frameworks". Now the SharedTestFramework compiles correctly, and as you can see in the workspace I uploaded, the SampleAppTests target is able to use it successfully.
Old and busted answer
Are you building a separate framework that is designed to be imported into test targets? If that's the case then I think you just need to reference XCTest.framework from this custom framework you're building.
On the other hand, if you're trying to add this extension to a framework that is used by your app target, that seems like a bad idea, because it would mean linking XCTest.framework to the binary that goes to the store and runs on people's devices.
I'm not sure if that's possible. I'm more confident that it's not a scenario Apple expects or supports.