Archive for iPhone
iPhone objective-c and c++
April 4th, 2010 • iPhone
if you want to use c++ files in your iphone app do this:
- rename the FILE.m in FILE.mm
- import the .cpp class
Sample
#import "Foo.cpp" - (void)aFunction:() { Foo foo = *(new Foo(123)); NSString *objcString = [NSString stringWithUTF8String:foo.testStr.c_str()]; NSLog(@"string test: %@", objcString); NSLog(@"foo id start: %i", foo.myId); foo.setId(30303); NSLog(@"foo id: %i", foo.myId); }
foo class
#include <string> class Foo { public : int myId; public : std::string testStr; public : Foo(int startVal) { testStr = "Hallo Welt21212! äöü ß"; myId = startVal; }; public : void setId(int newId) { myId = newId; }; public : void test() { } };