EXC_BAD_ACCESS error in Objective-C - ios

I'm trying to write a simple iOS program that will notify when headphones are plugged/unplugged. I'm very new to Objective-C and iOS, and a lot of this code was written by somebody else and I'm now trying to adapt it so I'm having issues figuring out this problem. The code is here:
AppDelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
static void onHeadsetChange(void *, AudioServicesPropertyID, UInt32, const void *);
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.headsetOnHandler = self.headsetOffHandler = ^{};
NSLog(#"%lu", AudioSessionInitialize(NULL, NULL, NULL, NULL));
NSLog(#"%lu", AudioSessionSetActive(true));
NSLog(#"%lu", AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, &onHeadsetChange, (__bridge void *)self));
return YES;
}
static void onHeadsetChange(void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue) {
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
NSLog(#"The headset changed");
AppDelegate *const delegate = (__bridge AppDelegate *)inUserData;
const CFDictionaryRef routeChangeDictionary = inPropertyValue;
const CFNumberRef routeChangeReasonRef = CFDictionaryGetValue(routeChangeDictionary, CFSTR(kAudioSession_AudioRouteChangeKey_Reason));
SInt32 routeChangeReason;
CFNumberGetValue(routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
switch (routeChangeReason) {
case kAudioSessionRouteChangeReason_NewDeviceAvailable:
//NSLog([delegate description]);
[delegate headsetOnHandler];
break;
case kAudioSessionRouteChangeReason_OldDeviceUnavailable:
[delegate headsetOffHandler];
break;
default:
break;
}
}
#end
ViewController.m
#import "ViewController.h"
#implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
AppDelegate *delegate = (AppDelegate *)([UIApplication sharedApplication].delegate);
delegate.headsetOnHandler = ^{ self.view.backgroundColor = [UIColor greenColor];};
delegate.headsetOffHandler = ^{ self.view.backgroundColor = [UIColor redColor];};
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I'm getting the EXC_BAD_ACCESS error, code=1 at [delegate headsetOnHandler] and [delegate headsetOffHandler]. If I need to include the .h files for this to make sense, I will, and if there's anything else I'm missing please let me know.
EDIT:
I've added in declarations that people thought should be added:
#property (readwrite, assign) void (^headsetOnHandler)(void);
#property (readwrite, assign) void (^headsetOffHandler)(void);

How is the headsetOnHandler and headsetOffHandler properties declared?
If it is assign or retain, that is likely the source of your problem. Since they are blocks, it needs to be copy (even, in certain cases, under ARC). If they are atomic and retain, then your getter will call, effectively, [[block retain] autorelease] in the getter, which would explain your crash.
A bit of a long shot.
when you have a crash, always post the backtrace
when you know the line of code the crash is on, always post the variable declarations of any variables on that line
Note that ARC will change this behavior a bit, automatically handling the blocks in some cases, but -- IIRC -- you would still need to copy them in this case.

Related

cloudsight cloudSightQuery parameters set to null

I am trying to implement the CloudSight API into an iOS Objective C project for fun, however for some reason when I try to send an image to cloudSight the cloudSightQuery parameters are all set to null.
I have added CloudSight to my application as a Cocoapod and everything loads fine and when I execute this code below it just never returns any kind of response from the server in fact I'm not even sure it sends.
firstview.h
#import <UIKit/UIKit.h>
#import "CloudSight.h"
#import <CloudSight/CloudSightQueryDelegate.h>
#interface FirstViewController : UIViewController <CloudSightQueryDelegate>
{
CloudSightQuery *cloudSightQuery;
}
- (void)searchWithImage;
- (NSData *)imageAsJPEGWithQuality:(float)quality;
#end
firstview.m
#import "FirstViewController.h"
#import <CoreLocation/CoreLocation.h>
#import "CloudSightConnection.h"
#import "UIImage+it_Image.h"
#import <CloudSight/CloudSightQuery.h>
#interface FirstViewController ()
#end
#implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
cloudSightQuery.queryDelegate = self;
[self searchWithImage];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)searchWithImage {
UIImage * myImage = [UIImage imageNamed: #"car.jpg"];
NSData *imageData = [self imageAsJPEGWithQuality:0.7 image:myImage];
// Start CloudSight
cloudSightQuery = [[CloudSightQuery alloc] initWithImage:imageData
atLocation:CGPointZero
withDelegate:self
atPlacemark:nil
withDeviceId:#""];
[cloudSightQuery start];
}
#pragma mark CloudSightQueryDelegate
- (void)cloudSightQueryDidFinishIdentifying:(CloudSightQuery *)query {
if (query.skipReason != nil) {
NSLog(#"Skipped: %#", query.skipReason);
} else {
NSLog(#"Identified: %#", query.title);
}
}
- (void)cloudSightQueryDidFail:(CloudSightQuery *)query withError:(NSError *)error {
NSLog(#"Error: %#", error);
}
#pragma mark image
- (NSData *)imageAsJPEGWithQuality:(float)quality image:(UIImage *)image
{
return UIImageJPEGRepresentation(image, quality);
}
#end
Here's the library: https://libraries.io/github/cloudsight/cloudsight-objc
We just updated the library to make this clearer. You can run a pod update CloudSight to get the new version.
The most typical cause of this sort of problem is that the delegates are never being called. Usually, that means that the delegate object is released before being called back, however in this case it looks like it's nil when assigned.
This line here:
cloudSightQuery.queryDelegate = self;
[self searchWithImage];
Should be changed to:
[self searchWithImage];
And then in the method implementation change the initialization and start to:
// Start CloudSight
cloudSightQuery = [[CloudSightQuery alloc] initWithImage:imageData
atLocation:CGPointZero
withDelegate:self
atPlacemark:nil
withDeviceId:#""];
cloudSightQuery.queryDelegate = self;
[cloudSightQuery start];
Let us know if that helps!

IOS-Convert code-based interface to Storyboard based interface

I am referencing a IOS project that use code to create the interface rather than storyboard file.
But my project is using storyboard to build the user interface.
Right Now, all my file compile pretty well, but just do not run.
I keep getting "Thread 1:signal SIGABRT" error.
Below are my project file:
AppleDelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
AppDelegate.m
#import "AppDelegate.h"
#import "DetectionViewModel.h"
#import "ViewController.h"
#import "RscMgr.h"
#interface AppDelegate ()
#end
#implementation AppDelegate{
#private
UIWindow* _mainWindow;
RscMgr* _serialManager;
ViewController* _viewController;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_serialManager = [[RscMgr alloc] init];
DetectionViewModel* detectionViewModel = [[DetectionViewModel alloc] initWithSerialManager: _serialManager];
_viewController = [[ViewController alloc] initWithViewModel: detectionViewModel];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#import <opencv2/videoio/cap_ios.h>
#import <opencv2/imgcodecs/ios.h>
using namespace cv;
#class DetectionViewModel;
#interface ViewController : UIViewController<CvVideoCameraDelegate>{
IBOutlet UIImageView* imageView;
// IBOutlet UIButton* startButton;
CvVideoCamera* videoCamera;
}
#property (nonatomic, retain) CvVideoCamera* videoCamera;
//- (IBAction)startButton:(id)sender;
-(instancetype)initWithViewModel:(DetectionViewModel*)viewModel;
#end
ViewController.m
#import "ViewController.h"
#import "DetectionViewModel.h"
#import "opencv2/videoio/cap_ios.h"
#import "opencv2/imgcodecs/ios.h"
#interface ViewController ()
#end
#implementation ViewController
{
#private
DetectionViewModel* _viewModel;
}
-(instancetype)initWithViewModel:(DetectionViewModel *)viewModel{
self = [super init];
if(self){
_viewModel = viewModel;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//serial Manager process
//
//camera
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.delegate =self;
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset1920x1080;
// self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideo
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 20;
self.videoCamera.grayscaleMode = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Protocol CvVideoCameraDelegate
#ifdef __cplusplus
- (void)processImage:(cv::Mat &)image{
Mat imageCopy,imageCopy2,imageCopy3,imageCopy4;
cvtColor(image, imageCopy, COLOR_BGRA2BGR);//cvtColor(image, image, COLOR_BGR2GRAY);
cvtColor(imageCopy, imageCopy2, COLOR_BGR2HSV);//bitwise_not(imageCopy, imageCopy);
GaussianBlur(imageCopy2, imageCopy3, cv::Size(5,5),0, 0);//smooth the image with gaussian blur
cv::inRange(imageCopy3, cv::Scalar(100,127.5,28.05,1), cv::Scalar(131,255,137.7,1), imageCopy4);//recognize blue
// cv::inRange(imageCopy3, cv::Scalar(0,0,0,0), cv::Scalar(180,255,40,0), imageCopy4);//recognize black in HSV
//other:threshold(imageCopy, image, 0, 255, 0);
/*****************************find the contour of the detected area abd draw it***********************************/
//2-D point to store countour
std::vector< std::vector<cv::Point>> contour1;
int erosionSize = 3;//do opening on the binary thresholded image
Mat erodeElement = getStructuringElement(cv::MORPH_ELLIPSE,cv::Size(2*erosionSize+1,2* erosionSize+1), cv::Point(erosionSize,erosionSize));
erode(imageCopy4, imageCopy4, erodeElement);
dilate(imageCopy4, imageCopy4, erodeElement);
cv::findContours(imageCopy4, contour1, RETR_EXTERNAL, CHAIN_APPROX_NONE);//Acual line to find the contour
Scalar color1 = Scalar(50,50,50);//set the color used to draw the conotour
for(int i=0; i< contour1.size(); i++){//loop the contour to draw the contour
drawContours(image, contour1, i, color1);
}
/****************************find the contour of the detected area abd draw it***********************************/
/****************************Appproximate the contour to polygon && get bounded Rectangle and Circle*************/
std::vector<std::vector<cv::Point>> contours_poly(contour1.size());
std::vector<cv::Rect> boundedRect(contour1.size());
std::vector<cv::Point2f> circleCenter(contour1.size());
std::vector<float> circleRadius(contour1.size());
for (int i=0; i< contour1.size(); i++){
approxPolyDP(Mat(contour1[i]), contours_poly[i], 3, true);
boundedRect[i] = boundingRect(Mat(contours_poly[i]));
minEnclosingCircle((Mat)contours_poly[i], circleCenter[i], circleRadius[i]);
}
/*****************************draw the rectangle for detected area ***********************************************/
Scalar recColor = Scalar(121,200,60);
Scalar fontColor = Scalar(0,0,225);
int largestContourIndex=0;
for (int i=0; i<contour1.size(); i++){ //find the largest contour
if(boundedRect[i].area()> boundedRect[largestContourIndex].area())
largestContourIndex=i;
}
int j=largestContourIndex;
for (int i=0; i< 2/*contour1.size()*/; i++){ // draw all contours // draw Rect for the largest contour
if(contour1.size()>0){
if(boundedRect[j].area()>40){
rectangle(image, boundedRect[j].tl(), boundedRect[j].br(), recColor);
cv::Point fontPoint = boundedRect[j].tl();//show text at tr corner
putText(image, "Blue", fontPoint, FONT_HERSHEY_COMPLEX, 3, fontColor);
}
}
}
}
#endif
#pragma mark - UI Actions
- (IBAction)startVideoCamera:(UIBarButtonItem *)sender {
[self.videoCamera start];
}
- (IBAction)stopVideoCamera:(UIBarButtonItem *)sender {
[self.videoCamera stop];
}
- (IBAction)openWheel1:(UIBarButtonItem *)sender {
[_viewModel sendMessage:#"w1Open"];
}
- (IBAction)openWheel2:(UIBarButtonItem *)sender {
[_viewModel sendMessage:#"w2Open"];
}
#end
DetectionViewModel.h
#import <Foundation/Foundation.h>
#class RscMgr;
#interface DetectionViewModel : NSObject
-(instancetype)initWithSerialManager:(RscMgr*)serialManager;
-(void) sendMessage:(NSString*)message;
#end
DetectionViewModel.m
#import "DetectionViewModel.h"
#import "RscMgr.h"
#interface DetectionViewModel() <RscMgrDelegate>
#end
#implementation DetectionViewModel
{
#private
RscMgr* _serialManager;
}
-(instancetype)initWithSerialManager:(RscMgr* )serialManager{
self = [super init];
if(self){
_serialManager = serialManager;
[_serialManager setDelegate:self];
}
return self;
}
-(void)sendMessage:(NSString *)message{
[_serialManager writeString:message];
}
#pragma mark - Delegate
-(void)cableConnected:(NSString *)protocol{
}
-(void)cableDisconnected{
}
-(void)portStatusChanged{
}
-(void)readBytesAvailable:(UInt32)length{
}
#end
in Console:
I have following info:
2015-04-05 21:19:22.310 XRoverVideoProcessingTest[852:198728] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main' in bundle NSBundle (loaded)'
* First throw call stack:
(0x184c2a530 0x195bac0e4 0x189a04484 0x1896c4590 0x1896c3728 0x1896c1f1c 0x18d0f1604 0x184be2d70 0x184be1e78 0x184be0078 0x184b0d1f4 0x1894a3020 0x18949e10c 0x10005fd68 0x19622aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
And I did add the storyboard file name into the info list
It looks to me like perhaps the storyboard file was not added to the build target, so it can't be found at launch time

Can an Objective-C object remove itself in its method (ARC is enabled)?

In some reason, I have to use a design pattern that an object remove itself from its container, consider the following code(ARC is enabled, LCDObject is an object class, LCDContainer is a container class), in the whole program, object 's reference count is always 1 until it is removed from the container(reference count become 0), as comment 2 mention, when [_container removeObject:self] return, the object's reference count is 0, it is dealloc, right?, but the process is still in the object's method -- "removeFromContainer", what would happen? Does the following code would be execute successfully? Does "removeFromContainer" can return successfully?
I run this code in Xcode, the "NSLog" in "removeFromContainer" can be invoked successfully, but I can't figure out why...
//-------------------------------------------------------------
#import <Foundation/Foundation.h>
#interface LCDContainer : NSObject
#property (strong, nonatomic) NSMutableArray *objects;
- (void)removeObject:(id)object;
- (id)addObject:(id)object;
#end
#implementation LCDContainer
- (id)init {
self = [super init];
if (self) {
_objects = [[NSMutableArray alloc] init];
}
return self;
}
- (id)addObject:(id)object {
[_objects addObject:object];
return object;
}
- (void)removeObject:(id)object {
[_objects removeObject:object];
}
#end
//-------------------------------------------------------------
#interface LCDObject : NSObject
#property (weak, nonatomic) LCDContainer *container;
- (id)initWithContainer:(LCDContainer*) container;
- (void)removeFromContainer;
#end
#implementation LCDObject
- (id)initWithContainer:(LCDContainer *)container {
self = [super init];
if (self) {
_container = container;
// (1) add the object to the Container, now its reference count is 1
//
[container addObject:self];
NSLog(#"add to container.");
}
return self;
}
- (void)removeFromContainer {
// (2) remove the object from the Container, now its reference count is 0,
// the object is delete, does the following "NSLog" would be invoked successfully?
//
[_container removeObject:self];
NSLog(#"remove from container.");
}
#end
//-------------------------------------------------------------
int main(int argc, const char * argv[]) {
#autoreleasepool {
LCDContainer *container = [[LCDContainer alloc] init];
[[LCDObject alloc] initWithContainer:container];
[[[container objects] objectAtIndex:0] removeFromContainer];
}
return 0;
}
I've not tried your code but I suspect it will work. sapi's suggestion (adding a breakpoint or NSLog on dealloc) is a good one to confirm, though.
Thee are two ways that ARC could be doing this. You can check the assembler if you're really interested.
The simplest is to assume that it's using autorelease, that is, when an object is removed from your container it gets added to the autorelease pool and is released (and dealloced) at the end of the current run loop.
The other way is to consider where ARC adds its retains and releases. This question notes that your remove method really looks like this:
- (void)removeObject:(id)object {
[object retain];
[_objects removeObject:object];
[object release];
}
The call to removeObject: may well have the same logic. This means that object does not get released as soon as the removeObject: call is completed; the object lifecycle is almost certainly (slightly) longer than that.

Referencing a ViewController in AppDelegate - Objective C

I am trying to get a NSMutableArray from another class. I am trying to reference that ViewController that contains the array. Lets say, a has the array I want. b is the class I am going to get that array in.
a.h:
#property (strong, nonatomic) NSMutableArray *selectedCells;
a.m:
#synthesize selectedCells;
AppDelegate.h:
#property (strong, nonatomic) a *create_challengeDelegate;
AppDelegate.m:
#synthesize create_challengeDelegate;
a *create_challengeDelegate = [[a alloc]init];
Right here when I try to reference that ViewController I get an error saying:
Initializer element is not a compile-time constant
I assume it has something to do with it not being able to see the ViewController.
In my b.m:
AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
app.create_challengeDelegate.selectedCells
My issue is working with initializing the ViewController in the delegate.
Suggestions and thoughts on that?
My suggestion is that you create the selectedCells array in you AppDelegate and send it to A. E.g. in:
AppDelegate.h
#property (nonatomic, strong) NSArray *selectedCells;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.selectedCells = [NSMutableArray array];
A *viewA = [[a alloc] initWithNibName:#"a" bundle:nil selectedCells:self.selectedCells];
[...]
}
a.h
#property (nonatomic, strong) NSMutableArray *selectedCells;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil selectedCells:(NSMutableArray*)cells;
a.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil selectedCells:(NSMutableArray*)cells
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.selectedCells = cells;
}
return self;
}
b.m
AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
NSMutableArray *selectedCells = app.selectedCells;
This way, whenever you make changes to selectedCells it will keep it in the array you send there since selectedCells is a refference to an object which is created in your AppDelegate.
Otherwise, what you are trying to do is access a view which might no longer be available in the memory since the view might have been deallocated.
Also, you create the instance of a but its not set to the AppDelegate's instance of a, its a seperate instance.
Instead of
#synthesize create_challengeDelegate;
a *create_challengeDelegate = [[a alloc]init];
You should have
#synthesize create_challengeDelegate;
self.create_challengeDelegate = [[a alloc] init];
I still strongly recommend you do not access your view this way though.
P.s. #synthesize is no longer necessary.
Edit
This is a better solution.
Selection.h
/**
* The entity for selections
*/
#interface Selection : NSObject
/**
* The Shared Instance
*
* #return Selection The instance
*/
+ (Selection *)sharedInstance;
/**
* Add an item to the selections
*
* #param object id The object to add
*/
- (void)addSelection:(id)object;
/**
* Remove an item from the selections
*
* #param object id The object to remove
*/
- (void)removeObject:(id)object;
/**
* Get the selections
*
* #return NSArray The array with the current selection objects
*/
- (NSArray *)getSelections;
#end
Selection.m
#import "Selection.h"
#interface Selection ()
#property (nonatomic, strong) NSMutableArray *selections;
#end
#implementation Selection
#pragma mark - Public methods
+ (Selection *)sharedInstance
{
static Selection *sharedInstance = nil;
#synchronized(self) {
if (sharedInstance == nil) {
sharedInstance = [[self alloc] init];
}
}
return sharedInstance;
}
#pragma mark - Private methods
- (id)init
{
if (self = [super init])
{
self.selections = [NSMutableArray array];
}
return self;
}
#pragma mark - Manage selection
- (void)addSelection:(id)object
{
[self.selections addObject:object];
}
- (void)removeObject:(id)object
{
[self.selections removeOjbect:object];
}
- (NSArray *)getSelections
{
return [NSArray arrayWithArray:self.selections];
}
Now you can assess your shared singeton in A and/or B by accessing:
[[Selection sharedInstance] addObject:myObject];
[[Selection sharedInstance] removeObject:myObject];
NSArray *array = [[Selection sharedInstance] getSelections];
Is this line inside a method:
a *create_challengeDelegate = [[a alloc]init];
If not that would probably explain your issue. If that's not the problem it might be helpful to post more complete code.

NSCoder game data storage/retrieve sanity check

Just wanted to get a sanity check on this code for storing and retrieving user data for iOS 7. It's not working but I'm not seeing the issue.
GameData.h
#import <Foundation/Foundation.h>
#interface GameData : NSObject<NSCoding>
{
int HighScoreGD;
}
#property (readwrite,assign) int HighScoreGD;
#end
extern GameData *gGameData;
GameData.m
#import "GameData.h"
GameData *gGameData;
#implementation GameData
#synthesize HighScoreGD;
-(void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInt:HighScoreGD forKey:#"HighScoreGD"];
}
-(id)initWithCoder:(NSCoder *)coder {
if((self = [super init])) {
HighScoreGD = [coder decodeIntForKey:#"HighScoreGD"];
}
return self;
}
-(id) init {
if((self = [super init])) {
}
return self;
}
-(void) dealloc {
//[super dealloc];
}
#end
Storing data:
gGameData.HighScoreGD = pointsHigh;
Retrieving data:
pointsHigh = gGameData.HighScoreGD;
I had used this in a bunch of old game concepts (cocos2d) in the past and it worked fine.
Not getting compile errors. Just simply isn't storing the data.
I haven't used this code in a couple years and it's not working. Did iOS7 or cocos2d v3 change how NSCoder is used?
Or am I making a dumb error somewhere?
Thanks in advance.

Resources