Library only accessible from AppDelegate - ios

I'm trying to get a library to work on my Swift project via Cocoapod.
I've created a Bridging header file, and I'm importing the headers of my library in there. When I try to instantiate an object from a class of this library in my AppDelegate, I get no issues.
Trouble comes when I try to do the same thing from any other file. I have Use of unresolved identifier 'FooBar'.
I've tried to import the library manually instead of using Cocoapod,
but no luck.
I've also tried to use a different library but I'm met with the exact
same problem.
XCode doesn't seem to have any problems with the Bridging file, I've
created my own and I get no complaints at compile.

Related

Xcode Import Objective-C, Objective-C++ project into Swift Project

I am trying to integrate this https://github.com/gareth-cross/kalman-ios project with my own Swift project in Xcode.
When building the project I receive 2 errors:
kalman-ios/matrix.hpp:28:10: error: 'cmath' file not found
failed to emit precompiled header
'/Users/.../Build/Intermediates.noindex/PrecompiledHeaders/Tron-iOS-Bridging-Header-
swift_J9ENU1M0P5CE-clang_M49XZJR5TLTE.pch'
for bridging header '/Users/.../Filter/Tron-iOS-Bridging-Header.h'
My project is purely Swift, and the kalman-ios project is a mixture of ObjC and ObjC++.
My bridging header file is:
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "KFEstimator.h"
For more context, the kalman-ios project is structured as:
KFEstimator.mm makes calls to AttitudeESKF.cpp makes calls to matrix.cpp
My initial thought was the cmath file error was the cause for the bridging header error. But I have almost no experience outside Swift and don't know how to go about fixing it. Up until yesterday, I wasn't even aware that you could use ObjCPP.
Any help is appreciated!
I have solved the issue. I was mistaken and believed that the repository was Objective-C making calls to Objective-C++.
It was actually all Objective-C++.
I was able to make direct calls to the Objective-C++ functions by following this video guide.

Cannot import Swift code into Objective-C in spite of following recommended settings. Manual bridging possibility?

I cannot get my swift files imported into my Obj-C project. I know, there’s a lot already on this topic on stack overflow, and I’ve tried all answers in this thread on importing Swift code to Objective-C, but I've still got the same error in spite of what I've tried for my project called Plantasia:
When at the top of the script of the .m file of a pre-existing project I do
import "Plantasia-Swift.h"
I get file not found error.
What I've tried:
I've set for both project and example
"Defines Module" : YES
"Always Embed Swift Standard Libraries" : YES
"Install Objective-C Compatibility Header" : YES
Changed the Project Module Name to Plantasia
I’ve cleaned my build folder and tried a bunch of unlikely solutions like #import "Plantasia/Plantasia-Swift.h" , which don't work either.
I’ve tried prepending #objc to class declaration in the .swift file.
I’ve tried manually adding another bridging header, and specifying the "Swift Compiler – Code Generation" to my header.
I've tested starting from a blank Objective-C project, by creating a Swift file, and referenced it successfully within .m file. This shows that it's at least working normally for me in a clean project
I've been trying for hours, and I think there must be one incorrect setting somewhere that I'm unaware of. I've tried basically most of what I could find on the forums. Any additional ideas of things I should still check? Or is there a way of manually creating this "Plantasia-Swift.h" header file?

Objective c client generated from swagger-codegen is not working properly when imported mannually in project

I have generated Objective c client from swagger.json. And imported the generated source in my Xcode project by Right clicking on project then choosing Add Files to "ProjectName". As swagger-codegen generated source has dependency on ISO8601, JSONModel and AFNetworking, so i downloaded them and added in my project. Project is building successfully but it is not working properly. When i invoke any API call by using functions inside Api folder it is unable to invoke function inside Core folder. I tried putting debug point in function inside Core folder but flow of control is not reaching there, and Xcode is not showing any error either.
Surprisingly generated code is working fine if i add it as cocoapod dependency.
But i don't want to use cocoapod in my project.
What step am i missing in importing it manually? And why Xcode is not throwing any error?
If you are importing the dependancies manually instead of using cocoapods then you have to change the import statements from
#import <JSONModel/JSONModel.h>
to
#import "JSONModel.h"
and the same for all of the AFNetworking imports
Finally i found the problem "Pheww!", Hope it may help others.
Actually i was using frameworks of all three dependencies, and app was crashing at start. I found somewhere that making them Optional in Linked Frameworks and Libraries will stop the app from crashing, and indeed crash gone.
But doing that caught me in this weird schenario.
So the solution for this problem is to keep them Required and add one New Copy Files Pahse in Build Phases and choose Frameworks in destination. I renamed that as Embed Framework.
new copy files phase
And just cross verify the frameworks, In General tab
enter image description here

Importing a library in to an Xcode 7 project

So I am trying to add a static library to my project in order to interface with a scanner. I have linked the binary in build phases to the libCaptuvoSDK.a, put the Captuvo.h header file in the project folder, and finally set the project to always search the user paths and added $(BUILT_PRODUCTS_DIR) recursive to the user header search paths. After doing all this I am trying to use #import "Captuvo.h" in my ViewController.swift file and getting the 2 errors Expected identifier in import declaration, and Expected expression. I have tried different combinations of importing and none of them seem to make a difference so I am led to believe the issue is with my process of adding the library.
I am new to Xcode and have never used a third party library in an application before so I feel I may be making a simple mistake or just misinterpreting things. Any help is appreciated!
Okay so I managed to fix my issue! I had imported the static library properly but the real issue was the header file. I fixed my issue by creating a new file in my projects folder named Quick-Scan-Bridging-Header.h. Inside that file is where the #import "Captuvo.h" line belonged. Once that was done I opened the Quick Scan apps build settings and under Objective-C Bridging Header I added the path Quick Scan/Quick-Scan-Bridging-Header. I also added the Header Search Path $(BUILT_PRODUCTS_DIR)
After I did all this I am able to use the Captuvo classes in my ViewController.swift file.

swift: weak cannot be applied to an outlet

I am using libzBar for scanning QRCode in swift but I am getting these errors.
.
First error is about weak referencing and second is undeclared type.
At first I thought I haven't included the ZBarReaderView.h but after checking the file Inspector I found that the files are correctly added as
I have already added a ZBarReaderView in Objective-C and it works fine. I have also viewed the sample project for adding an EmbeddedReader(ObjectiveC).
So I want to know why I am getting this error and how to remove this error?
Solution:
To import a set of Objective-C files in the same app target as your
Swift code, you rely on an Objective-C bridging header to expose those
files to Swift. Xcode offers to create this header file when you add a
Swift file to an existing Objective-C app, or an Objective-C file to
an existing Swift app.
It looks like you didn't create a bridging header. Follow the Apple Docs to create one and then import ZBarReaderView.h in the bridging header.

Resources