简体   繁体   中英

Xcode objective-C errors need some help :)

Ok so been trying to figure this out for sometime I've managed to get it down to these 3 errors and Ive been looking for a fix but nothing is working can anyone help me with this?

Im trying to compile something and this is part of it this is all i need fixed to get it to work but i don't know what to do.

Also this is not my code if you want to see the original follow the link credit goes to Hamzasood

Hamzasood custom watch face

i put the error next to the code so look for <---//ERROR there are only 3

Here are the files below 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

Its missing content and is looking for something but I don't know I'm really new to this.

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

and this one gives expected method body

like i said I'm not good with this so if you can please help:)

At the top of .h You have @class compiler directive, without providing a name for the class that you're forward-declaring. The @class is used to "forward declare" a class, which tells the compiler "this other class X will exist, so don't complain about not knowing all the details yet." Since you don't provide a name, the compiler gets confused, so you see an error on the next line. See this question: Objective-C: @class Directive before @interface?

At the bottom of .m you have @class again for some reason... But the error seems to be because you put an open curly brace { after @implementation that isn't closed until after all the methods. That shouldn't be there. You use curly braces after @implementation if you want to declare instance variables. Not necessary for the methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM