So, I have to add a functionality to an old .cpp file.It's huge. So rewriting it in Objective C is not an option. Instead, I have added the necessary functionality using Objective-C (because I need a lot of the NSDate/NSDateFormatter functions). It worked fine. BUT, when calling the getter (on my view controller) I get this error: EXC_BAD_ACCESS.
Here is a fragment of the code:
//.h file -----------------
// C/C++ headers
#import <Foundation/NSDate.h>
#import <Foundation/NSDateFormatter.h>
namespace MySpace {
class Session {
private:
// C++ stuff
NSDate * startTime;
public:
// C++ stuff
NSDate * getStartTime();
Session(NSDate * startTime );
};
}
// .cpp file -----------------
using namespace MySpace;
Session:Session (NSDate * startTime) {
// unrelated code
if (startTime == nil ){
startTime = [NSDate date];
}
setStartTime( startTime);
// unrelated code
}
void Session::setStartTime( NSDate * startTime){
this->startTime = [startTime copy];
}
NSDate * Session::getStartTime() {
return this->startTime; // here I get the EXC_BAD_ACCESS
}
The entire project is compiled as Objective-C++ and ARC enabled. I believe this issue is caused because the member 'startTime' is released by ARC, and, when I call the getter, it points to nil?
How may I solve this problem?
Thanks.