我不断收到expected identifier or '('
以下代码。我想为我的学校项目做一个例子。任何人的帮助将不胜感激。这是整个脚本。
//
// ViewController.m
// Pocket Codez
//
// Created by Dinesh1201 on 10/9/14.
// Copyright (c) 2014 Dinesh and co. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
- (IBAction)Generate:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *Password;
@end
@implementation ViewController
- (IBAction)Generate:(id)sender {
struct label label = { .password = @"468392" };
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
错误位于
struct label label = { .password = @"468392" };
现在在编辑之后,并且说变量的类型不完整' struct label'
答案 0 :(得分:1)
您似乎暗示它是问题的struct
初始化,但是我不会期望该错误消息,但是初始化{的一个或多个成员的正确方法{1}}正在使用:
struct
当然,除非struct label label = { .password = @"468392" };
是类的属性或实例变量(该语句没用,所以我觉得缺少必要的信息才能完全回答你的问题。)
答案 1 :(得分:0)
的问题:
label.password = @"468392";
NSString
中设置struct
个对象。编译器不允许你这样做。password
声明为int
。//[1] define the struct
typedef struct {
int password;
//...
} labelStruct;
@interface ViewController ()
{
//[2] make struct variable
labelStruct label;
}
//...
@end
- (IBAction)Generate:(id)sender
{
//[3] apply value
label.password = 468392;
}