OptimusCrime
OptimusCrime

Reputation: 14863

Setting variable in another class in objective-c

I have a map-controller where the user can tab the map to add a new marker. The idea is then to store the coordinates in the new marker-class. The problem I am facing is setting those variables.

NewMarkerController.h

@interface NewMarkerController : UIViewController
{
    NSNumber *posLat;
    NSNumber *posLng;
}

@property (nonatomic, retain) NSNumber *posLat;
@property (nonatomic, retain) NSNumber *posLng;

@end

I am also synthesizing this in the .m file is that makes any difference.

MapController.m

NewMarkerController *vc = [[NewMarkerController alloc] init];
[vc posLat:coordinate.latitude];

The last line shows an error saying No visible @interface for 'NewMarkerController' declears the selector 'postLat', but...there is...?

Can anyone spot the problem I am having here?

Upvotes: 0

Views: 87

Answers (2)

talnicolas
talnicolas

Reputation: 14053

This syntax:

[vc posLat:coordinate.latitude]

means that posLat is a function of the vc kind of class. As you want to set a variable, if you synthesized it you can just do:

[vc setPosLat:coordinate.latitude]

or

vc.posLat = coordinate.latitude

Upvotes: 1

vikingosegundo
vikingosegundo

Reputation: 52227

[vc setPosLat:coordinate.latitude];

or

vc.posLat = coordinate.latitude;

Upvotes: 2

Related Questions