2013-02-23 3 views
2

방금 ​​iOS 개발을 시작했으며 경고로 인해 막혔습니다. 빌드가 성공적이지만이 경고는 나를 귀찮게합니다. 다른 답변을 확인했지만 잘못된 점을 파악하지 못했습니다.불완전한 구현 - Xcode 경고

경고의 - 당신은 이러한 속성의 getter를 구현하지 않은

Complexnumbers.h

#import <Foundation/Foundation.h> 

@interface ComplexNumbers : NSObject 

-(void) setReal: (double)a; 
-(void) setImaginary: (double)b; 
-(void) print; // display as a + bi 

-(double) real; 
-(double) imaginary; 

@end 

Complexnumbers.m

#import "ComplexNumbers.h" 

@implementation ComplexNumbers // Incomplete implementation 

{ 
double real; 
double imaginary; 
} 

-(void) print 
{ 
    NSLog(@"%f + %fi",real,imaginary); 
} 
-(void) setReal:(double)a 
{ 
    real = a; 
} 
-(void) setImaginary:(double)b 
{ 
    imaginary = b; 
} 

@end 
+0

"real"과 "imaginary"라는 2 개의 변수 *를 갖고 싶습니다. 맞습니까? 음, 대신에'real'과'imaginary'라고 불리는 2 * 함수가 있습니다.'.m' 파일에 함수로 구현되어 있지 않기 때문에,이 경고를 받고 있습니다 :). 여러분의 변수에 대해'@ property'와'@ synthesize'를 만드는 것에 대한 답 중 하나를 따르십시오. – Mxyk

+0

마이크가 맞습니다. 처음에는 약간 혼란 스럽습니다. 수업은 배웠다. :) – vDog

답변

2

불완전한 구현 :

-(double) real; 
-(double) imaginary; 

-(double) real { return _real; } 
-(double) imaginary { return _imaginary; } 

또는 헤더의 속성로 선언하여 당신을 위해 그것을 할 컴파일러를 보자 : 유 중 하나를 구현할 수 있습니다

@property(nonatomic) double real; 
@property(nonatomic) double imaginary; 

그리고하는 .m 파일 :

@synthesize real = _real, imaginary = _imaginary; 

여기서 _은 인스턴스 구성원입니다.

+0

제프의 답변에 감사드립니다. 나는 밑줄을 사용하고 그것들을 특성으로 재 선언했고 그것이해야하는 방식대로 작동했습니다. – vDog

3

인터페이스에 realimaginary 방법이 있지만 사용자가 구현하지 않았다고 문제가 있습니다. 더 나은 아직, 컴파일이 속성으로 정의하여 당신을위한 realimaginary 세터와 게터 방법을 합성하도록하고 코드가 크게 간소화된다

@interface ComplexNumbers : NSObject 

@property (nonatomic) double real; 
@property (nonatomic) double imaginary; 

-(void) print; // display as a + bi 

@end 

@implementation ComplexNumbers 

-(void) print 
{ 
    NSLog(@"%f + %fi", self.real, self.imaginary); 
} 

@end 
0

이 시도,

#import "ComplexNumbers.h" 

@implementation ComplexNumbers // Incomplete implementation 

{ 
double real; 
double imaginary; 
} 

-(void) print 
{ 
    NSLog(@"%f + %fi",real,imaginary); 
} 

-(void) setReal:(double)a 
{ 
real = a; 
} 
-(void) setImaginary:(double)b 

{ 
imaginary = b; 
} 
-(double) real 
{ 
    return real; 
} 
-(double) imaginary 
{ 
    return imaginary; 
} 

@end 
+0

실수가 있습니다. ivars에는 선행 밑줄이 없습니다. – rmaddy

관련 문제