5

名前と辺の数を設定できるアプリを作成しています。その後、アプリは形状の名前を自動的に計算します。辺の数を から に変更するように依頼されましNSNumberint。これを実行しましたが、「レシーバーの種類が正しくありません」というエラーが表示されます。これを修正し、サイド プロパティの数を維持するにはどうすればよいintですか?

これはクラスのヘッダーファイルです

#import <Foundation/Foundation.h>

@interface shape : NSObject

@property int *numberOfSides;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *colour;

@property (nonatomic, strong) NSString *calculatedName;

void waitOnCR (void);
- (NSString *)calculatedName;

@end

これはクラスの実装ファイルです

- (NSString *)calculatedName {
    if ([self.numberOfSides isEqual: @3]) {
        return self.name = @"Triangle";
    }
    else if([self.numberOfSides isEqual: @4]) {
        return self.name = @"Square";
    }
    else if([self.numberOfSides isEqual: @5]) {
        return self.name = @"Pentagon";
    }
    else if([self.numberOfSides isEqual: @6]) {
        return self.name = @"Hexagon";
    }
    else if([self.numberOfSides isEqual: @7]) {
        return self.name = @"Heptagon";
    }
    else if([self.numberOfSides isEqual: @8]) {
        return self.name = @"Octagon";
    }

    return [NSString stringWithFormat:@"%@", self.name ];
}

@end

これはメインファイルです

NSLog(@"Enter a number from between 3-8");

int user;

scanf("%d" , &user);

switch (user) {
    case 3:
    {
        shape *myShape = [[shape alloc]init];
        [myShape setNumberOfSides:3];
        [myShape setColour:@"Red"];
        id s2 = [myShape calculatedName];


        NSLog(@"The %@ shape has %i sides and is called a %@", [myShape colour], [myShape numberOfSides], s2);
        break;
    }
    case 4:
    {
        {
            shape *myShape = [[shape alloc]init];
            [myShape setNumberOfSides:@4];
            [myShape setColour:@"Blue"];
            id s2 = [myShape calculatedName];

            NSLog(@"The %@ shape has %@ sides and is called a %@", [myShape colour], [myShape numberOfSides], s2);
            break;
        }
    case 5:
        {
            shape *myShape = [[shape alloc]init];
            [myShape setNumberOfSides:@5];
            [myShape setColour:@"Orange"];
            id s2 = [myShape calculatedName];

            NSLog(@"The %@ shape has %@ sides and is called a %@", [myShape colour], [myShape numberOfSides], s2);
            break;
        }
    case 6:
        {
            shape *myShape = [[shape alloc]init];
            [myShape setNumberOfSides:@6];
            [myShape setColour:@"Purple"];
            id s2 = [myShape calculatedName];

            NSLog(@"The %@ shape has %@ sides and is called a %@", [myShape colour], [myShape numberOfSides], s2);
            break;
        }
    case 7:
        {
            shape *myShape = [[shape alloc]init];
            [myShape setNumberOfSides:@7];
            [myShape setColour:@"Green"];
            id s2 = [myShape calculatedName];

            NSLog(@"The %@ shape has %@ sides and is called a %@", [myShape colour], [myShape numberOfSides], s2);
            break;
        }
    case 8:
        {
            shape *myShape = [[shape alloc]init];
            [myShape setNumberOfSides:@8];
            [myShape setColour:@"Pink"];
            id s2 = [myShape calculatedName];

            NSLog(@"The %@ shape has %@ sides and is called a %@", [myShape colour], [myShape numberOfSides], s2);
            break;
        }

    }
    default:
        NSLog(@"Shape not found!");
        break;
}
4

1 に答える 1