Swift Package Manager with Xcode - Could not build Objective-C module - objective-c

I have a swift executable package that has a dependency on objective-c library package. I'm trying to use Xcode for executable package development but I'm getting Could not build Objective-C module 'objcpackage' error while editing the swift file which imports objective-c module. Compiling works both from Xcode and also directly from command line using swift build but as soon as I open the swift file with import of that objc package the error pops up.
I have used the SPM to generate xcodeproj.
Clean nor clean build directory, deleting generated module map from the xcodeproj or restarting Xcode did not help.
I have created Objective-C package with the following:
$ swift package init --type library
It contains only one header Sources/include/Foo.h:
#import <Foundation/Foundation.h>
#interface Foo: NSObject
#end
and one .m file:
#import "Foo.h"
#implementation Foo
#end
The Swift package was created with $ swift package init --type executable.
The Package.swift file looks like:
import PackageDescription
let package = Package(
name: "swiftpackage",
dependencies: [ .Package(url: "../objcpackage", majorVersion: 1) ]
)
The main.swift contains only:
import objcpackage
Xcode project was created with $ swift package generate-xcodeproj
Xcode Version: 8.2.1 (8C1002)
Swift Version: 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
How can I get rid of that error?

This sounds like a bug that was recently fixed in the package manager (https://bugs.swift.org/browse/SR-3121). Have you tried a recent snapshot from https://swift.org/download/?
I tested the package you describe with a recent version of Swift 3.1 and it worked fine.

Related

Linphone SDK OS X - vcard_grammar

I’m trying to integrate linphone-sdk-Mac from https://download.linphone.org/releases/macosx/sdk/ to my objective c app.
Basically what I’m doing is extracting zip file and import framework files to my project and then change all frameworks to “embed and sign” and then compile.
Program runs fine until I try to create the core, even using “ linphone_factory_create_core_with_config_3” or “ linphone_factory_create_core_3”, they all crash with the same error, that is “could not load grammar vcard_grammar because the file could not be located”.
Already tried to put grammar files in several places of the project, on different versions, including last one, but with no luck.
Anyone know anyway to solve this?
Sample code:
LinphoneFactory *factory = linphone_factory_get();
NSString *linphonecfg = [LinphoneManager bundleFile:#"linphonerc"];
NSString *fileStr = [NSString stringWithContentsOfFile:linphonecfg encoding:NSUTF8StringEncoding error:nil];
configDb = linphone_config_new_from_buffer(fileStr.UTF8String);
theLinphoneCore = linphone_factory_create_core_with_config_3(factory, configDb, NULL);
Already tried to compile linphone-desktop but that is failing in random places every time I try to compile it, so could not solve that way.
Thanks
So after a lot of tinkering with the SDK, I've figured out to fix the vCard issue and compile properly without it on macOS with Swift/Objective-C (for arm64 and x86_x64).
Compiling SDK
Install the following dependencies with homebrew:
brew install pkg-config cmake doxygen nasm yasm
Install pip3/python3 (if you haven't already) and it's dependencies:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
pip3 install pystache
pip3 install six
Clone the latest Linphone SDK and it's dependencies recursively
git clone --recursive https://gitlab.linphone.org/BC/public/linphone-sdk
Make and set the build directory (-DENABLE_VCARD=OFF is the key here):
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_VCARD=OFF ..
cmake --build .
Xcode Integration
(if the build succeeded, hopefully)
In your build folder, go into your linphone-sdk/desktop folder
You should see a couple of different folder but the most important ones are Frameworks and share
Add the Frameworks and share folder into your Xcode project with the following options checked:
If you're using Swift, you will need to create a Objective-C bridging header with the following lines to avoid a giant list of errors in your LinphoneWrapper.swift in the share/linphonesw folder:
#import "linphone/factory.h"
#import "linphone/types.h"
#import "linphone/core.h"
#import "linphone/call.h"
#import "linphone/tunnel.h"
#import "linphone/wrapper_utils.h"
#import "linphone/core_utils.h"
#import "linphone/vcard.h"
#import "belle-sip/object.h"
#import "bctoolbox/list.h"
#import "mediastreamer2/msfactory.h"
In the Frameworks, Libraries, and Embedded Content section of your apps target, every framework should be "Embed & Sign".
Try compiling and accessing Core, Factory, etc... in a Swift file and it should work, if it doesn't, comment below and I'll try to help you out!

lldb in objective-c project that contain swift file

I have one static lib objective-c target ,and I add swift in it;
In Bridging-Heade file I import "Class.h" that is subclass of JSONModel ;
when use lldb po, it show "error: failed to import bridging header error: 'Class.h' file not found"
any can helps?
Go to your project -> Build settings -> search SWIFT_OBJC_INTERFACE_HEADER_NAME.
Check that it is Class.h. if not then check below.
You should import the value of SWIFT_OBJC_INTERFACE_HEADER_NAME in objective-c files (.h).
The the Bridging-Header file is in SWIFT_OBJC_BRIDGING_HEADER(search this key in Build setting), that is only reference for compiler. When you build project compiler generates .h file, the name is in SWIFT_OBJC_INTERFACE_HEADER_NAME.

Objective-C Class Not Found In Swift Bridging Header

I am updating our Cordova framework and I am stuck on getting a particular Objective-C plugin class to work.
In my old (un-updated) project everything works just fine. I have a BridgingHeader.h file, its properly referenced in the build settings. However in my new updated project it can no longer find only one Objective-C class (PushPlugin.m).
What's strange is its finding all other Objective-C classes just fine, its just the PushPlugin.m it can't find.
Here is my BridgingHeader:
#import <Cordova/CDV.h>
#import <objc/runtime.h>
#import <Parse/PFObject.h>
#import <Parse/PFSubclassing.h>
#import <Parse/Parse.h>
#import <objc/message.h>
#import "GPUImage.h"
#import "PushPlugin.h" // This one is not found
#import "CDVParsePlugin.h"
And when I try to use PushPlugin I get not found error:
//AppDelegate.swift
let pushHander:PushPlugin = getCommandInstance("PushPlugin") as! PushPlugin
// ERROR: PushPlugin not found
To be extra certain, the PushPlugin file is referenced in the Compile Sources. And my BridgingHeader is properly referenced in the build settings.
Do you have any idea why one specific Objective-C class is not being found?
Update
So to be clear, there is no error reporting the BridgingHeader file. Its only when I try to use the PushPlugin that I encounter the error (meaning its not importing properly).
As suggested I ran a commandline build I got a build failed with these reasons:
** BUILD FAILED **
The following build commands failed: CompileSwift normal arm64
/Users/user/Desktop/mobile-cordova-upgrade/app/platforms/ios/App/Classes/AppDelegate.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)

CocoaPods Failed to Lint A Podspec Due to Objective-C Generated Interface Header Not Found

When I tried to build a pod which some Swift files importing the project's Objective-C generated interface header( something likes YourProductModuleName-Swift.h ), it was always failed to build and said that the Objective-C generated interface header cannot be found.
How can I make the CocoaPod to correctly recognize the Objective-C generated interface header?

iOS xCode how to purge Objective C++ from a project?

I got a demo project that had a single Objective C++ source file. I removed the file and renamed all files that touched it from .mm to .m . However, xCode still thinks that there is Objective C++ code in my project and refuses to refactor class names, etc:
I tried deleting the file I want to refactor from xCode project using Delete > Remove references, then re-added it. The file has .h and .m, nowhere does it import any .mm files. xCode still would not refactor, complaining about objective C++.
How can I disable/ purge Objective C++ from an xCode 5.1 project if I already removed and renamed all files? Is there some build setting I need to flip?
Apple Update Objective-C version 2.0 then they enable feature to allow C++ language variant with GNU & clang Compiler with certain restriction
Anyway
Apple & development team know why remove Objective-C++
But in Current Objective-C++ project not open And you Stuck So simply Go to your Project Folder And Rename Objective-C++ project file extension from .mm to .m , still work as well
What Objective-C++ Remove