lldb in objective-c project that contain swift file - objective-c

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.

Related

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

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.

How do I get the compiler to see my Framework module.modulemap umbrella header?

I am building a framework with mixed Objective-C and Swift source files.
I've created my own module map file named module.modulemap.
My problem is that the compiler compiles only my umbrella header file when I put in the absolute path:
How do I get the compiler/Xcode to see the header file?
Ok, so I've found the issue. (Or one of them). It seems that to be able to use an umbrella header, the header must be an actual header file. In this case I was just using the only header file in the project, which also had a .m file.
My solution was to create an actual UmbrellaHeader.h file with the following contents:
#ifndef UmbrellaHeader_h
#define UmbrellaHeader_h
#include "TestObject.h"
#endif /* UmbrellaHeader_h */
FYI: If your project has its Headers phase before Compile Sources and you try to create a mixed Objective-C/Swift framework, you can see Swift compiler errors about the umbrella header being missing. If you remove/rename all .swift files the project will build fine, then putting them back it will build a second time, but a clean build fails.
Just move the Headers phase earlier in the build process and it should work.

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

Using GLM .obj loader in an Objective-C program

I am trying to use GLM to load a .obj object in my Objective-C Program (Xcode 4.4 Mac Os X). I have added the glm folder to my project. i try to import it using #import "glm/glm.hpp", but the program doesn't build. some of the errors are the following: (this errors are produced in the GLM files)
namespace glm{ //Unknown type name 'namespace'
namespace detail
{ .....
It doesn't find the cstdlib, cmath, and other libraries.
This happens because my program is in Objective-c and the GLM doesn't work with this language?
Those are all symptoms of trying to compile a C++ application with a C compiler. Namespace is a C++ keyword, and cstdlib, cmath, etc. are C++ names for standard C headers. You'll have to migrate your project to Objective-C++ to be able to use GLM.
Any files that uses the GLM library will require that file extensions to be renamed to .mm as it uses Objective-C++. Also, as it is only a file, and not a framework, you only need to put #import "glm.hpp"

How to compile specific files in objective-c++ and the rest of the project in objective-c

I'm currently busy on a project where I need to use an external accessory to read Mifare 1k tags.
The accessory was provided with an SDK, written in (Objective ?)C++ and I followed the instructions provided to set XCode to "Compile sources as: Objective-C++" and added "-Obj-C++" in "Other linkers flags.
The SDK compiles fine then, but trouble is I am already using several libraries in the project (such as ASIHTTPRequest, JSONKit, ...) and I get compilation problems because of those new settings in those libraries. If I switch back to the previous settings, I get compilation problems in the reader's SDK
The question is: is there a way to compile only the class from the SDK as C++ and the rest of the project as objective-c ?
Edit: the SDK files consists only of .h (and a linked library)
thanks for your help,
Mike
Select the file you want to compile as Objective C++ from the file navigator, and then select the File Type in the file inspector view. This is in Xcode 4, but there is a similar mechanism in Xcode 3.
Try renaming the files where you are including the library headers to myClass.h for interface and myClass.mm for implementation files. This forces the files to be compiled as objective-c++.
I have resolved this problem:
You should set "According to file type" to "Complile Sources As",
Set "-ObjC++" to the "Other Linker Flags"
The last,you should modify the files's suffix to .mm that reference
the library method
well, in Build phases tab, there is a section Compile sources. For file you want to use Objective-C++ compiler add flag: -xobjective-c++
tested in Xcode 12.5