我想在Objective-C iPhone应用程序中使用一些C++ STL集合.显然,这可以通过为文件提供扩展名".mm"来实现.有什么与此相关的怪癖/惊喜?
我想使用我熟悉的基本容器(矢量,队列,集合......)
干杯!
Cocoa使用typedef-ed匿名枚举位域.
我正在使用Objective-C++,无论好坏.在.mm文件中,我需要将2位(按位包含OR)分配给这些枚举位域类型之一的类型的属性.libc ++编译器不会拥有它,因为它不会为该typedef-ed匿名枚举位域的属性提供类型为int的rvalue.
我知道C&C++之间存在枚举的大小差异.那么这种情况的解决方法是什么?
执行作业的我的行类似于:
uiSwipeRightDownRecogniser.direction = Right | Down;
Run Code Online (Sandbox Code Playgroud)
位域的定义类似于:
typedef enum
{
Right = 1 << 0,
Left = 1 << 1,
Up = 1 << 2,
Down = 1 << 3
} UISwipeDirection;
Run Code Online (Sandbox Code Playgroud)
错误是:
无法使用类型为'int'的rvalue初始化'UISwipeDirection'类型的参数
这种赋值在.m文件中工作,但不是.mm.
编译器是Apple的LLVM 3.0(使用libc ++).
我有一个 Objective-C 类,其中一个变量是 C++ 对象(我的大部分代码是 C++,但我需要一些 ObjC 类来与 iOS 库集成)。Objective-C++ 是否保证在销毁Objective-C 对象时C++ 对象会被正确销毁?
一些示例代码:
class MyCppClass {
// ...
};
@interface MyObjCClass : NSObject {
MyCppClass myCppObject; // is it ok to do it?
}
// ...
@end
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的 iOS 应用程序编写 XCTest 单元测试。我正在使用 XCode 5.1.1。
我遇到的问题是,当我包含一个头文件,其中包含一个看起来像这样的头文件时,
#include <google/protobuf/stubs/common.h>它抱怨找不到该文件。
google我已在测试目标的标头搜索路径中包含了包含该文件夹的目录的相关路径。我已将其标记为始终使用搜索路径并递归搜索。
我的应用程序目标发现该路径没有任何问题,并且我以完全相同的方式包含它。我的单元测试类是 Objective-C++ 类,因为我已将文件名更改为.mm扩展名。
有什么想法为什么我会遇到找不到文件的问题吗?
这段代码
virtual const core::matrix4& getViewMatrixAffector() const {return core::matrix4();};
Run Code Online (Sandbox Code Playgroud)
结果有一个警告告诉我“返回对本地临时对象的引用”......
如何解决这个警告?
如下所述,我试图删除“&”...

我需要在C++类的Objective c中编写一个包装类.
我已经提到了以下无法找到标准C++包括在Cocoa项目中使用C++类时能够摆脱词法或预处理器问题:'vector'文件未找到问题.
但是,我不明白将C++方法转换为接受客观c方法的几个参数.
有人可以帮我这样做吗?我想要做的是为此http://breakfastquay.com/rubberband/code-doc/classRubberBand_1_1RubberBandStretcher.html#a0af91755d71eecfce5781f2cd759db85编写一个包装类
我试过这样做,以下是我坚持的方法......
// Wrapper.h
#import <Foundation/Foundation.h>
@interface Wrapper : NSObject {
void *myRubberBandStretcher;
}
#pragma mark - Member Functions
-(void)process:(const float)input samples:(size_t)samples final:(bool)final;
@end
Run Code Online (Sandbox Code Playgroud)
////////////////////////////////////////////////// ///////////////////////////////
//Wrapper.mm
#import "Wrapper.h"
#import "RubberBandStretcher.h"
@implementation Wrapper
-(id)init {
self = [super init];
if (self) {
myRubberBandStretcher = new RubberBand::RubberBandStretcher::RubberBandStretcher(44100, 2, 0, 1.0, 1.0);
}
return self;
}
-(void)process:(const float)input samples:(size_t)samples final:(bool)final {
static_cast<RubberBand::RubberBandStretcher *>(myRubberBandStretcher)->process(<#const float *const *input#>, <#size_t samples#>, <#bool final#>)
}
Run Code Online (Sandbox Code Playgroud) 将 C++ 组件添加到通过命令行编译和运行的 Swift 应用程序后,我现在需要编译 C++ 和 Objective-C++ (*.mm) 文件并将它们与 Swift 应用程序链接。
生成文件:
all: foo-renderer
clean:
rm -f foo-renderer cpp.o objc.o
cpp.o: FooRenderer/FooRenderer/FooLibrary.cpp
clang++ -c -o $@ $^
objc.o: cpp.o FooRenderer/FooRenderer/FooLibraryWrapper.mm
clang++ -c -framework Foundation -o $@ $^
foo-renderer: objc.o FooRenderer/FooRenderer/*.swift
xcrun -sdk macosx swiftc -import-objc-header FooRenderer/FooRenderer/FooRenderer-Bridging-Header.h -o $@ $^
Run Code Online (Sandbox Code Playgroud)
编译器失败并出现以下错误:
ld: warning: object file (objc.o) was built for newer OSX version (10.12) than being linked (10.9)
Undefined symbols for architecture x86_64:
"__ZN11FooLibrary23printifyERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE", referenced from:
-[FooLibraryWrapper printify:] in objc.o
"__ZN11FooLibrary8optimizeERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE", …Run Code Online (Sandbox Code Playgroud) 我似乎在将相机设置为以 240 FPS 录制时遇到问题,但由于某种原因,输出文件仅为 30 FPS。
这是我设置相机的代码(首先实例化):
class HFRCamera {
public:
HFRCamera();
AVCaptureDeviceInput *camera;
AVCaptureDeviceInput *microphone;
AVCaptureDevice *videoCam;
AVCaptureDevice *audioInput;
AVCaptureSession *capSession;
void start();
void config();
void stop();
};
HFRCamera::HFRCamera() {
// Set up capture session and add video camera and microphone
this->capSession = [[AVCaptureSession alloc] init];
this->videoCam = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
this->config();
}
void HFRCamera::start() {
[this->capSession startRunning];
}
void HFRCamera::stop() {
[this->capSession stopRunning];
}
void HFRCamera::config() {
const CGFloat desiredFPS = 240;
AVCaptureDeviceFormat *selectedFormat = nil;
AVFrameRateRange *frameRateRange = …Run Code Online (Sandbox Code Playgroud) 我有一个使用 Objective C++ 和一些外部 C++ 库的 iOS 应用程序,该应用程序使用 Crashlytics 来跟踪可能的用户崩溃。
Crashlytics 愉快地处理来自 Objective C 领域的所有异常,这在过去帮助我很多来追踪问题,我想从 C++ 端获取相同类型的崩溃日志,无论何时抛出任何异常。
不幸的是,当 std::exception 被调用时,我在 Crashlytics 中得到的只是一个不包括原点的通用堆栈跟踪,这无助于解决这些问题,也无助于任何 std 异常进入相同的事实一刀切累积的“崩溃”类型。
我可以捕获这些异常并以某种方式重定向它们,以便它们出现在 Objective C 发起的崩溃旁边吗?
我正在尝试类似的东西,但我似乎无法让它工作,同时保持 Crashlytics 处于相同的工作状态,我错过了什么吗?
我正在考虑的另一个可能的解决方案是捕获 C++ 异常并使用 Crashlytics 本身将它们记录为错误,然后从包装器中重新抛出它们。
https://docs.fabric.io/apple/crashlytics/logged-errors.html
未处理的 C++ 异常后的示例堆栈跟踪:
Crashed: com.twitter.crashlytics.ios.exception
0 MyApp 0x100d9baac CLSProcessRecordAllThreads + 4312709804
1 MyApp 0x100d9baac CLSProcessRecordAllThreads + 4312709804
2 MyApp 0x100d9b968 CLSProcessRecordAllThreads + 4312709480
3 MyApp 0x100d8b6b8 CLSHandler + 4312643256
4 MyApp 0x100d99ac4 __CLSExceptionRecord_block_invoke + 4312701636
5 libdispatch.dylib 0x182556a14 _dispatch_client_callout + 16
6 …Run Code Online (Sandbox Code Playgroud) What are the methods of developing for iOS with C++? I am familiar with using Objective-C++ within Xcode, by selecting Obj-C as my language when creating a new project, but what else is there. I know there are tools like Xamarin that allow for iOS development in C#, however i'm curious as to what officially supported ways of developing for iOS in C++ there are? Can an iOS app be written completely in C++ with no Objective-C and …
objective-c++ ×10
c++ ×7
ios ×6
objective-c ×5
xcode ×4
avfoundation ×1
bitmask ×1
c ×1
clang ×1
cocoa ×1
crashlytics ×1
irrlicht ×1
rubber-band ×1
swift ×1
xctest ×1