在消息发送表达式的开头缺少“[" [英] Missing '[' at start of message send expression

查看:33
本文介绍了在消息发送表达式的开头缺少“["的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误消息并匹配我的括号,但没有发现任何错误.你能找出什么问题吗?我真的需要帮助.请.我得到的错误是在消息发送表达式开始时缺少‘[’"我已经评论了它在我的代码末尾附近发生的位置.请帮帮我.

谢谢.

@interface HomeViewOne()@结尾@implementation HomeViewOne- (id)initWithNibName:(NSString *)nibNameOrNil 包:(NSBundle *)nibBundleOrNil{self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];如果(自我){//自定义初始化}回归自我;}- (void)viewDidLoad{[超级viewDidLoad];//从其笔尖加载视图后进行任何其他设置.}- (void)didReceiveMemoryWarning{[超级 didReceiveMemoryWarning];//处理任何可以重新创建的资源.}- (IBAction)switchScreenHome:(id)sender {//从主菜单切换屏幕到游戏的代码ViewController *view [[ViewController alloc] initWithNibName:nil bundle:nil];//我的错误在这一行,它说在消息发送表达式的开头缺少'['[self presentModalViewController:view animation:YES];}@结尾

解决方案

代码缺少一些有用的东西,比如 =.

因此[..]没有以有意义的方式解析(即作为赋值中使用的表达式)并导致给定的语法错误.><小时>

代码实际上被解析为一个变量数组声明,考虑

X* x[..];

.. 在哪里

[ViewController alloc] initWithNibName:nil bundle:nil

导致在消息发送表达式的开头缺少 '['",就像该代码本身出现在语句中一样.添加另一对 [] 将修复"该问题,并实际声明一个 可变长度数组.但是,您绝对不想在这里使用 VLA .. 只需添加赋值运算符即可.

I am getting this error message and matched my brackets and couldn't find anything wrong. Can you find what's wrong? I really need help. Please. The error I am getting is this "Missing '[' at start of message send expression" I have commented where it occurs down near the end of my code. Please help me.

Thank you.

@interface HomeViewOne ()

@end

@implementation HomeViewOne

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)switchScreenHome:(id)sender {

    //Code to switch screen from main menu to game
    ViewController *view [[ViewController alloc] initWithNibName:nil bundle:nil];  //My error is on this line, it says Missing '[' at start of message send expression
    [self presentModalViewController:view animated:YES];
}
@end

解决方案

The code is missing something useful, like an =.

Thus the [..] is not parsed in a meaningful fashion (i.e. as an expression used in an assignment) and results in the given syntax error.


The code is actually parsed as an variable array declaration, consider

X* x[..];

where .. is

[ViewController alloc] initWithNibName:nil bundle:nil

which results in "Missing '[' at start of message send expression", just as if that code appeared in a statement by itself. Adding another pair of []'s would "fix" that, and actually declare a variable-length array. However, you definetly don't want a VLA here.. just add the assignment operator already.

这篇关于在消息发送表达式的开头缺少“["的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆