for debugging purposes my ProfileObj currently only has one NSString variable that is being saved, and the code runs fine while that NSString is nil (currently loaded from Player[0]) but when the string has data the app crashes at [archiver encodeObject:profile forKey:kDatakey]; and i cannot figure out why or how to fix it. This is my first time ever trying to save data and any help would be greatly appreciated!
Is the .Name property declared as (nonatomic,retain) ? If it's not set to retain then the string will probably get dealloc'd before you go to use it. Do you always use the .Name property when changing the Name variable?
Yes the .Name is declared as (nonatomic, retain) . Currently i do always use .Name to change the variable. Would adding setter and getter methods fix my problem?
the part that's throwing me off is it crashes at [archiver encodeObject:profile forKey:kDatakey] only when .Name contains data.
I further narrowed down the error, commenting out the [encoder encodeObject:Name forKey: kNameKey]; line inside the encodeWithCoder: method results in no data saved while leaving it results in a crash regardless if .Name has a value or not.
I further narrowed down the error, commenting out the [encoder encodeObject:Name forKey: kNameKey]; line inside the encodeWithCoder: method results in no data saved while leaving it results in a crash regardless if .Name has a value or not.
any clue what i'm doing wrong?
Sounds like the value of Name is bad at the time of encoding. Put a breakpoint at that line in your code and look at the Name instance variable. I'm guessing that you are assigning it without using property syntax, so it's not invoking the (retain) setter, and is getting released.
if you ever have code like this:
Code:
Name = [NSString stringWithFormat: @"blah blah blah %d", somevar];
Then Name won't be retained, and you will probably crash at some future date when you try to reference it.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
I used a breakpoint and .Name DOES contain data at the time of encoding, but right after checking that i saw a typo, I put endodeObject: instead of encodeObject: , after fixing that everything works fine. God i feel silly
I used a breakpoint and .Name DOES contain data at the time of encoding, but right after checking that i saw a typo, I put endodeObject: instead of encodeObject, after fixing that everything works fine. God i feel silly
thanks for the help
Oops.
You really, really have to check for warnings when you compile. I daresay you got a warning when you first compiled it. The really bad thing about warnings is that they only show up the first time you compile. If you don't check them the first time, the warning isn't repeated until you change the file in which it occurs.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.