Getter Setter:与指针转换不兼容的整数将'int'发送到'int *'类型的参数

时间:2014-06-09 06:39:04

标签: ios objective-c getter-setter

我正在尝试创建getter setter模块并应用于我的Control类

当涉及编译时,不兼容的整数到指针转换将'int'发送到'int *'类型的参数会显示在代码的最后一行:

  CheckPoints *myCar=[[CheckPoints alloc] init];
    [myCar setState:1];

以下是我的CheckPoints.m,CheckPoints.h

的.m

#import "CheckPoints.h"

@implementation CheckPoints

@synthesize desp = _desp;
@synthesize latitude = _latitude;
@synthesize longitude = _longitude;
@synthesize state = _state;


- (NSString *) getDesp
{
    return desp;
}

- (float *) getLatitude
{
    return latitude;
}

- (float *) getLongitude
{
    return longitude;
}

- (int *) getState
{
    return state;
}

- (void)setDesp:(NSString *)valueDesp {
    [self setDesp:valueDesp];
}

- (void)setLatitude:(float *)valueLatitude {
  //  self.latitude = valueLatitude;
    [self setLatitude:valueLatitude];
}

- (void)setLongitude:(float *)valueLongitude {
    [self setLongitude:valueLongitude];
}

- (void)setState:(int *)valueState {
    [self setState:valueState];
}

@end

·H

#import <GoogleMaps/GoogleMaps.h>
#import <Foundation/Foundation.h>

@interface CheckPoints : NSObject<CLLocationManagerDelegate> {

    NSString *desp;
    float *latitude;
    float *longitude;
    int *state;
}


@property (nonatomic, assign) NSString* desp;
@property  (nonatomic, assign) float* latitude;
@property  (nonatomic, assign) float* longitude;
@property  (nonatomic, assign) int* state;

- (NSString *)getDesp;
- (Float32 *)getLatitude;
- (Float32 *)getLongitude;
- (int *)getState;

- (void)setDesp:(NSString *)valueDesp;
- (void)setLatitude:(float *)valueLatitude;
- (void)setLongitude:(float *)valueLongitude;
- (void)setState:(int *)valueState;

@end

1 个答案:

答案 0 :(得分:2)

你应该删除&#39; *&#39;标量类型的标志。换句话说,您应该将其更改为:

- (void)setState:(int)valueState {
    [self setState:valueState];
}