ios - How to Pass Custom class Object using NSUser Defaults in iphone SDK? -


this question has answer here:

in app, have custom class file.

i try using objectforkey shows me null value & give error in console

[nsuserdefaults setobject:forkey:]: attempt insert non-property value '<fsvenue: 0x181898c0>' of class 'fsvenue'. note dictionaries , arrays in property lists must contain property values.

how can pass object of custom class view?

code custom class follow:

fsvenue.h

#import <uikit/uikit.h> #import <corelocation/corelocation.h> #import <mapkit/mapkit.h>  @interface fslocation : nsobject{     cllocationcoordinate2d _coordinate; }  @property (nonatomic, assign) cllocationcoordinate2d coordinate; @property (nonatomic,strong)nsnumber*distance; @property (nonatomic,strong)nsstring*address;  @end   @interface fsvenue : nsobject<mkannotation>  @property (nonatomic,strong)nsstring*name; @property (nonatomic,strong)nsstring*venueid; @property (nonatomic,strong)fslocation*location;  @end 

fsvenue.m

#import "fsvenue.h"       @implementation fslocation       @end      @implementation fsvenue       - (id)init     {         self = [super init];         if (self) {             self.location = [[fslocation alloc]init];         }         return self;     }      -(cllocationcoordinate2d)coordinate{         return self.location.coordinate;     }      -(nsstring*)title{         return self.name;     }   @end 

you need make sure custom object implements nscoder class. the nscoder abstract class declares interface used concrete subclasses transfer objects , other objective-c data items between memory , other format.

here tutorial shows how.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -