Xcode objective-C错误需要一些帮助:)



好的,所以一直试图找出这个时间我已经设法得到了这3个错误,我一直在寻找一个修复,但没有工作,谁可以帮助我这个?

我试图编译一些东西,这是它的一部分,这是所有我需要修复,让它的工作,但我不知道该怎么做。

这也不是我的代码如果你想看原始的遵循链接的功劳归于Hamzasood

Hamzasood定制表盘

我把错误放在代码旁边,所以查找<——//error只有3个

以下是文件1. onozomgeditingguideview.h

//
//  OnozOmgEditingGuideView.h
//  CustomWatchFaceTest
//
//  Created by Hamza Sood on 17/08/2015.
//  Copyright © 2015 Hamza Sood. All rights reserved.

#import <UIKit/UIKit.h>
@class
@interface OnozOmgEditingGuideView : UIView {   <---//expected identifier
    UIView *_topView;
    UILabel *_topLabel;
    UIView *_bottomView;
    UILabel *_bottomLabel;
}
@end
/*!
 Set the color shown by the top view.
    The new color to be displayed
*/
- (void)setTopColor:(UIColor *)color;
/*!
 Set the color shown by the bottom view.
 @param color
    The new color to be displayed
 */
- (void)setBottomColor:(UIColor *)color;   <---//missing content for method declaration

它缺少内容,正在寻找一些东西,但我不知道,我真的是新的。

2. onozomgeditingguideview.m

//
//  OnozOmgEditingGuideView.m
//  CustomWatchFaceTest
//
//  Created by Hamza Sood on 17/08/2015.
//  Copyright © 2015 Hamza Sood. All rights reserved.
//
#import "OnozOmgEditingGuideView.h"
@implementation OnozOmgEditingGuideView {    <---//Expected Method Body
/*
 Initial setup steps:
    1. Create the views and their corresponding labels
    2. Set the label text
    3. Constrain the views
*/
- (instancetype)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // 1
        __strong UIView  **viewsToCreate[]  = { &_topView,       &_bottomView };
        __strong UILabel **labelsToCreate[] = { &_topLabel, &_bottomLabel };
        for (int i = 0; i < sizeof(viewsToCreate)/sizeof(UIView**); i++) {
            UIView *view = [[UIView alloc]initWithFrame:CGRectZero];
            [view setTranslatesAutoresizingMaskIntoConstraints:NO];
            [self addSubview:view];
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectZero];
            [label setTranslatesAutoresizingMaskIntoConstraints:NO];
            [view addSubview:label];
             NSLayoutAttribute labelAttributesToConstrain[] = { NSLayoutAttributeCenterX, NSLayoutAttributeCenterY };
            for (int j = 0; j <     sizeof(labelAttributesToConstrain)/sizeof(NSLayoutAttribute); j++) {
                NSLayoutConstraint *constraint = [NSLayoutConstraint   constraintWithItem:label
                                                                                  attribute:labelAttributesToConstrain[j]
                                                                                 relatedBy:NSLayoutRelationEqual
                                                                                     toItem:view
                                                                                attribute:labelAttributesToConstrain[j]
                                                                             multiplier:1
                                                                                  constant:0];
                [constraint setActive:YES];
            }
            *viewsToCreate[i] = view;
            *labelsToCreate[i] = label;
        }
        // 2
        [_topLabel setText:@"First Colour"];
        [_bottomLabel setText:@"Second Colour"];
        // 3
        NSString *constraintsToAdd[] = {
            @"H:|[_topView]|",
            @"H:|[_bottomView]|",
            @"V:|[_topView]-(0)-[_bottomView(==_topView)]|"
        };
        NSDictionary *constraintsViewsDictionary =  NSDictionaryOfVariableBindings(_topView, _bottomView);
        for (int i = 0; i < sizeof(constraintsToAdd)/sizeof(NSString*); i++) {
            [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:constraintsToAdd[i]
                                                                                                options:0
                                                                                             metrics:nil
                                                                                               views:constraintsViewsDictionary]];
        }
    }
    return self;
}
@class
- (void)setTopColor:(UIColor *)color {
    [_topView setBackgroundColor:color];
}
- (void)setBottomColor:(UIColor *)color {
    [_bottomView setBackgroundColor:color];
}
@end

这个给出了预期的方法体

就像我说的,我不擅长这个,所以如果你可以帮助:)

在。h的顶部,你有@class编译器指令,没有为你正向声明的类提供名称。@class用于"前向声明"一个类,它告诉编译器"另一个类X将存在,所以不要抱怨还不知道所有的细节。"由于没有提供名称,编译器会感到困惑,因此您会在下一行看到错误。看看这个问题:Objective-C: @class指令在@interface之前?

在。m的底部,由于某种原因你又有了@class…但是错误似乎是因为你在@implementation之后放了一个开花括号{,直到所有方法之后才关闭。它不应该在那里。如果要声明实例变量,则在@implementation后面使用大括号。

最新更新