FROM : Gerriet M. Denkmann
DATE : Sun Nov 21 13:53:09 2004
On 21.11.2004, at 13:00, Jonathan Jackel wrote:
>
> On Nov 21, 2004, at 4:47 AM, Gerriet M. Denkmann wrote:
>
>> I have an object, which I want to archive.
>>
>> - (void)encodeWithCoder:(NSCoder *)coder
>> {
>> [ coder encodeObject: myString forKey: @"myString" ];
>> }
>>
>> - (id)initWithCoder:(NSCoder *)decoder
>> {
>> myString = [ decoder decodeObjectForKey: @"myString" ];
>> NSLog("@ myString: \"%@\");
>> return self ;
>> }
>>
>> When myString is @"$noll" everything works just fine.
>> But if myString is @"$null" (note the changed vowel) the unarchive
>> string is nil.
>
> Four things:
>
> 1. Always call super in your init method. Always.
Yes, you are right. Now my initWithCoder: starts with:
self = [ super init ];
if ( self == nil ) return nil ;
>
> 2. Your NSLog statement looks wrong. There's no parameter and no
> closing quote mark (the escape sequence at the end doesn't count).
> And the first @ should go outside the first quote mark.
Right again; as you sure have already realized, this statement has
never been compiled - it was just typed in Mail. And I have to
apologize for the sloppy typing.
It should have been:
NSLog(@"myString = %@", myString);
>
> 3. Use accessors to set ivars. Otherwise your ivars will be
> deallocated prematurely. This could be your problem.
Well, as I log the value immediately after decodeObjectForKey: there is
not much chance for premature deallocation.
>
> 4. I think it is a good practice to use constant strings, defined
> outside the implementation, as keys. That way you will get a compiler
> warning if you type them incorrectly. For example:
I agree that this is a good practice; but alas, it has nothing to do
with my problem.
>
> Try it that way and see if you still have problems.
I did and I still have.
I can archive and restore a string with the value "$noll" but I cannot
do the same with "$null".
Kind regards
Gerriet.
DATE : Sun Nov 21 13:53:09 2004
On 21.11.2004, at 13:00, Jonathan Jackel wrote:
>
> On Nov 21, 2004, at 4:47 AM, Gerriet M. Denkmann wrote:
>
>> I have an object, which I want to archive.
>>
>> - (void)encodeWithCoder:(NSCoder *)coder
>> {
>> [ coder encodeObject: myString forKey: @"myString" ];
>> }
>>
>> - (id)initWithCoder:(NSCoder *)decoder
>> {
>> myString = [ decoder decodeObjectForKey: @"myString" ];
>> NSLog("@ myString: \"%@\");
>> return self ;
>> }
>>
>> When myString is @"$noll" everything works just fine.
>> But if myString is @"$null" (note the changed vowel) the unarchive
>> string is nil.
>
> Four things:
>
> 1. Always call super in your init method. Always.
Yes, you are right. Now my initWithCoder: starts with:
self = [ super init ];
if ( self == nil ) return nil ;
>
> 2. Your NSLog statement looks wrong. There's no parameter and no
> closing quote mark (the escape sequence at the end doesn't count).
> And the first @ should go outside the first quote mark.
Right again; as you sure have already realized, this statement has
never been compiled - it was just typed in Mail. And I have to
apologize for the sloppy typing.
It should have been:
NSLog(@"myString = %@", myString);
>
> 3. Use accessors to set ivars. Otherwise your ivars will be
> deallocated prematurely. This could be your problem.
Well, as I log the value immediately after decodeObjectForKey: there is
not much chance for premature deallocation.
>
> 4. I think it is a good practice to use constant strings, defined
> outside the implementation, as keys. That way you will get a compiler
> warning if you type them incorrectly. For example:
I agree that this is a good practice; but alas, it has nothing to do
with my problem.
>
> Try it that way and see if you still have problems.
I did and I still have.
I can archive and restore a string with the value "$noll" but I cannot
do the same with "$null".
Kind regards
Gerriet.
| Related mails | Author | Date |
|---|---|---|
| Gerriet M. Denkman… | Nov 21, 10:47 | |
| Jonathan Jackel | Nov 21, 13:00 | |
| Gerriet M. Denkman… | Nov 21, 13:53 | |
| Joakim Danielson | Nov 21, 15:09 | |
| Gerriet M. Denkman… | Nov 21, 19:31 | |
| Joakim Danielson | Nov 21, 20:15 |






Cocoa mail archive

