Xcode 上奇怪的编译时错误

发布于 2024-12-14 03:01:19 字数 938 浏览 3 评论 0原文

中的代码

xcode 4.2 Game Model.h

#import <Foundation/Foundation.h>

@interface Game_Model : NSObject{
    NSString  *playerName;
    int play;
    int won;
}

@property (nonatomic,retain) NSString *playerName;
@property (nonatomic,readonly,assign) int play;
@property (nonatomic,readonly,assign) int won;
@end

Game Model.m

#import "Game Model.h"

@implementation Game_Model
@synthesize playerName,play,won;

+(NSString *)description{
    return [NSString stringWithFormat:@"%@. Player:%@. Score: %d/%d",[super description],self.playerName,self.won,self.play];
}
@end

我完全(或几乎完全)按照书中的方式制作,但我收到错误消息:

  • Objective-C 指针到 'struct objc_class 的隐式转换 *' 不允许与 ARC
  • 成员引用类型 'struct objc_class *' 为指针;也许您想使用“->”?
  • 类型“struct objc_class”的不完整定义自动引用计数问题:
  • Objective-C 指针隐式转换为“struct objc_class” ARC 不允许使用 *' 我根本不知道这些错误! 请帮我!

code in xcode 4.2

Game Model.h

#import <Foundation/Foundation.h>

@interface Game_Model : NSObject{
    NSString  *playerName;
    int play;
    int won;
}

@property (nonatomic,retain) NSString *playerName;
@property (nonatomic,readonly,assign) int play;
@property (nonatomic,readonly,assign) int won;
@end

Game Model.m

#import "Game Model.h"

@implementation Game_Model
@synthesize playerName,play,won;

+(NSString *)description{
    return [NSString stringWithFormat:@"%@. Player:%@. Score: %d/%d",[super description],self.playerName,self.won,self.play];
}
@end

I made exactly (or nearly exactly) as in a book, but I got error messages:

  • implicit conversion of an Objective-C pointer to 'struct objc_class
    *' is disallowed with ARC
  • member reference type 'struct objc_class *' is a pointer; maybe you meant to use '->'?
  • incomplete definition of type 'struct objc_class' Automatic Reference Counting Issue:
  • Implicit conversion of an Objective-C pointer to 'struct objc_class
    *' is disallowed with ARC
    I simply have no idea about these errors!
    Please help me!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独患者 2024-12-21 03:01:19

description 不是类方法,而是实例方法。您创建的是一个类方法:+(NSString*)description;。您不应尝试在类方法中访问实例属性 (ivars)。将+ 更改为-。祝你好运!

description is not a class method, but an instance method. What you create is a class method: +(NSString*)description;. You should not try to access instance properties (ivars) in a class method. Change + into -. Good luck!

鹿港小镇 2024-12-21 03:01:19

我认为您正在尝试引用此内容

[super description]

,这可能会使事情变得有点混乱,尝试在没有此内容的情况下返回,看看会发生什么

return [NSString stringWithFormat:@"Player:%@. Score: %d/%d",self.playerName,self.won,self.play];

I think that you are trying to refer to this

[super description]

and this might mess things around a little bit, try a return without that and see what happens

return [NSString stringWithFormat:@"Player:%@. Score: %d/%d",self.playerName,self.won,self.play];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文