swift project with cocoapods obj-c dependence - objective-c

I'm making a simple swift application which links an obj-c cocoapod dependency SFRoundProgressCounterView. My Podfile contains use_frameworks!. After installing pods and building the project I get 2 errors:
SFCounterLabel.h:12:9: 'TTTAttributedLabel.h' file not found
Could not build Objective-C module 'SFRoundProgressCounterView'
I checked that SFCounterLabel.h which is part of SFRoundProgressCounterView import TTTAttributedLabel:
#import "TTTAttributedLabel.h"
I tried to use MyProjectName-Bridging-Header.h with
#import "TTTAttributedLabel.h"
but without reason.
My version of Cocoapods is 0.39.0.
What should I do to link SFRoundProgressCounterView correctly to my swift project?

It looks like in SFCounterLabel.h SFRoundProgressCounterView needs to use the import syntax that supports frameworks. #import <TTTAttributedLabel/TTTattributedLabel.h> or #import TTTAttributedLabel.TTTAttributedLabel;

Related

warning: Swift error in module. Debug info from this module will be unavailable in the debugger

I have no debugging values in my console for my swift + obj-c app, and I get a really unhelpful message that explains why the debugger isn't working: "warning: Swift error in module XXX.". XXX is the name of my module, not a 3rd party that I include.
My app has been around since before Swift. I used the bridging header to start using Swift, and I recently used the Xcode tool to migrate all the Swift 2 files to Swift 3. (but I still have obj-c legacy in there). I use cocoapods, which may be contributing to the problem.
(lldb) po self
warning: Swift error in module XXX.
Debug info from this module will be unavailable in the debugger.
I tried following the second answer to this post and a couple others
I have found that suggest the same thing: remove duplicate imports.
I tried removing duplicate imports from my swift project. In fact if I run find . -name "*swift" | xargs grep "import" I get no results. So I went to the extreme of removing all imports from all of my swift files (and commenting out code to get it to compile) just to see if I can get my debugger to come back.
So...
Is there another solution to this problem?
Is there a way to get a more detailed error message?
Is it a problem to have duplicate headers in the my bridging header? For example, a lot of my obj-c files import UIKit, and I include a few of those files in the bridging header.
Just now I have encountered this problem.
This is my solution:
If you import 3rd repo by Cocoapods, and the repo is written by Objective-C, you need to import it by this way:
// System
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
// Directly add - Objective-C
#import "EaseUI.h"
// Cocoapods - Objcetive-C
#import MJRefresh;
You can refer to this issue in Github and this question.

Obj C project swift file cannot see cocoa pods

I have an Objective C project that I added a swift file to - the swift file will contain convenience functions to the rest of my objc project. Adding the swift file triggered adding a bridging header - which I did. All of this works. I also have cocoapods configured and working from objc.
I can call a swift method from objc but my swift file cannot see any of my swift cocoapod modules. I get error 'no such module'. I've searched here extensively and have cleaned my project, cleaned the build folder checked my search paths- all appears ok. I am using use_frameworks! In my pod file.
Any pointers?
You need to add your pod header to your bridging header as described here: Import Objective-C Framework (CocoaPod) into Swift?

Non-modular header inside framework module

I am creating a cocoapod (framework) in swift that needs to import a 3rd party objective-c framework. However, when adding #import <ThirdPartyFramework/ThirdPartyFramework.h> to the umbrella file of my cocoapod, I get the following error:
Include of non-modular header inside framework module 'MyCocoapod'
I tried setting Allow non-modular includes in framework modules to YES but that did not resolve the error.
The ThirdPartyFramework.h header just has a bunch of imports of other headers:
#import <ThirdPartyFramework/Header1.h>
#import <ThirdPartyFramework/Header2.h>
...
I can't really edit this framework since it's from a 3rd party. Is there anything I can do to use this 3rd party framework in my swift cocoapod? Can I not modularize the header that I need to import?
I've read here that the library owner needs to move the imports into a .m file, but I am not the library owner. Also, I'm using swift and the library is in objective-c so I don't really have .m files, which is why I have to import it in my umbrella file.
Using XCode 7.3

Module not found error when importing Swift pod into Objective-C project

I have an existing project which is written in Objective-C. I want to use the iOS Charts library by Daniel Gindi, which is in Swift, in that project. How can I achieve this?
importing swift framework into a objective-c project is related, but in my case I am using the library by installing it through Cocoapods as instructed here.
In that question, he is at least able to import the header, but in my case I am not able to.
step 1: Create Objective-C single view project.
step 2: Create a Podfile and add following lines -
use_frameworks!
pod 'Charts'
step 3: Install the pod
step 4: Try to import Charts in ViewController.h by #import Charts but it gives an error at this point. The error is - Module Charts not found
In my existing project, I did #include Charts-Swift.h in my project's main.m file and this solved problem from me. #import Charts worked perfectly now. This was done according to the instructions that are written in Apple documentation here.
I made a new project and tried Anni S's answer, this time I built the project with cmd+B before writing any import statement and it worked too. I guess building it once after installing pod and before importing any module is necessary.
I tried the same step what you mentioned in the comment however I was not getting the error that you got. My project simply builds and runs. Steps that I followed:
Create Objective-C single view project.
Added 'Podfile' in the project directory level (Podfile should be at the xcodeproject file level) and add following lines
use_frameworks!
pod 'Charts'
Close xcodeproject
Go to project directory and run the 'pod install' command from the termial
Open workspace i.e. .xcworkspace file
Import charts file in view controller such as
#import "ViewController.h"
#import Charts;
I found the reason why it works for new project, but for an existing project.
In the project settings, delete the value of the Other Linker Flags property.
This is the most case that most developers are being missed.

Can't use Objective-C Pod Framework in Swift 2 project ("Use of undeclared type 'SMPageControl'")

I have a Swift 2 project running on Xcode 7. I'm using CocoaPods (v 0.38.2 with use_frameworks!) and have already managed to get those frameworks working:
CryptoSwift
Pluralize_swift
Both Pods are written in Swift, so no problems so far. They work as charm.
Now I'm trying to use SMPageControl which is written in Objective-C. I've seen it's possible to use Obj-C Pods with Swift 2, tried a lot of different combinations but I can't get it to work. SMPageControl class doesn't show on autocomplete suggestions, and obviously when I try to use it the compiler throws Use of undeclared type 'SMPageControl'.
What I have done so far:
Added pod 'SMPageControl' to my Podfile
Ran pod install (I can see the Pod source/framework on Xcode project tree)
Added SMPageControl.framework in Build Phases > Link Binary With Libraries (as I've done with the other frameworks that work)
Created PROJECT_NAME-Bridging-Header.h and added it on the project's Build Settings (I can tell it's working because it threw errors until I got to import SMPageControl correctly)
Added #import <SMPageControl/SMPageControl.h> to the file above
Up to here the project compiles without errors, but I can't get to use SMPageControl in my Swift classes. Tried import SMPageControl in the Swift file, but no luck (it doesn't even autocomplete). I understood it's possible, but I didn't find any example codes.
Is it really possible? If so, what am I missing?
Finally got it to work, it turns out that I was actually missing something.
Along with all steps above, it's needed to import the framework at the top of the Swift file:
import SMPageControl
Since Xcode was not providing any autocomplete I thought it wouldn't be possible to do that. Once I added the import statement, the project compiled successfully and I was able to use SMPageControl() class.