小编use*_*959的帖子

目标C - 错误:'预期类型'

我对一些我认为简单的事情有一个非常奇怪的错误.

#import <Foundation/Foundation.h>
#import "ViewController.h"
#import "GameObject.h"


@interface GameController : NSObject 

@property (strong) GLKBaseEffect * effect;
@property (strong) NSMutableArray * gameObjects;
@property (strong) NSMutableArray * objectsToRemove;
@property (strong) NSMutableArray * objectsToAdd;


+ (GameController *) sharedGameController;
- (void) tick:(float)dt;
- (void) initializeGame: (ViewController*) viewcontroller;//ERROR: EXPECTED A TYPE

- (void) createObject:(Class) objecttype atPoint:(CGPoint)position;
- (void) deleteObject:(GameObject*) object atPoint:(CGPoint)position;
- (void) manageObjects;

@end
Run Code Online (Sandbox Code Playgroud)

为什么会问'ViewController'是否是一个类型?这是我正确实施的课程.它也被导入了.

编辑*

如果它有帮助,这是ViewController.m类.

#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[GameController sharedGameController] initializeGame:self];
}

@end
Run Code Online (Sandbox Code Playgroud)

编辑2 ** …

import objective-c circular-dependency header-files forward-declaration

16
推荐指数
1
解决办法
2万
查看次数

Objective C - 错误:线程1:EXC_BAD_ACCESS代码= 2

我在尝试调用方法时遇到错误.

方法

- (void)setSpeed:(GLKVector2)newSpeed{  //Error message (see title) points to here
    self.speed = GLKVector2Make(newSpeed.x, newSpeed.y);
}
Run Code Online (Sandbox Code Playgroud)

电话

[self setSpeed:GLKVector2Make(0, 0)];
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

objective-c

3
推荐指数
1
解决办法
1773
查看次数

Objective C - 如何实例化保存为变量的类

我是Objective C的新手,我对这个概念感到困惑.

以下方法应该创建作为参数传递的类的实例并编辑实例的变量.

- (void) createObject:(Class)objecttype atPoint: (CGPoint)position {

    if ([objecttype isSubclassOfClass:[GameObject class]]){

        id theobject = [[objecttype alloc] init];

        theobject.x = position.x; //error
        theobject.y = position.y; //error
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到上面显示的错误消息: Property 'x' not found on object of type '__strong id'

看起来它应该很简单,但我不明白什么是错的.

class objective-c instance

2
推荐指数
1
解决办法
146
查看次数