类“test_coredataAppDelegate"的重复接口声明 [英] duplicate interface declaration for class 'test_coredataAppDelegate'

查看:14
本文介绍了类“test_coredataAppDelegate"的重复接口声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码突然触发了两个错误- 类test_coredataAppDelegate"的重复接口声明- 'struct test_coredataAppDelegate'的重新定义

two errors suddenly fired in this piece of code - duplicate interface declaration for class 'test_coredataAppDelegate' - redefinition of 'struct test_coredataAppDelegate'

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>

@interface test_coredataAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

    ///////////////////New parts /////////////////////////
    NSManagedObjectModel *managedObjectModel;
    NSManagedObjectContext *managedObjectContext;       
    NSPersistentStoreCoordinator *persistentStoreCoordinator;

    //////////////////////////////////////////////
    UIWindow *window;
    UITabBarController *tabBarController;
}
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

请教如何解决

最好的问候

推荐答案

有两种可能:

  • 您有两个同名的接口.使用 Xcode 的 find in project 菜单选项来查找 test_coredataAppDelegate 的实例.然后重命名其中一个接口
  • 不知何故,您已成功导入 .h 文件两次.检查以确保您始终使用 #import 而不是 #include.
  • you have two interfaces with the same name. Use Xcode's find in project menu option to find instances of test_coredataAppDelegate. Then rename one of the interfaces
  • somehow you have managed to import the .h file twice. Check to make sure you always use #import and not #include.

关于 #import/#include 的更多信息:

A bit more info on #import/#include:

#include#include 语句的位置盲目地包含文件.这意味着如果您在 .m#include 一个文件两次,您将获得该文件的两个副本.几乎所有传统的 C #include 文件都包含以下内容:

#include blindly includes the file at the location of the #include statement. This means that if you #include a file twice in your .m you will get two copies of the file. Almost all traditional C #include files have something like the following bracketing all the content:

// some_file.h
#if !defined SOME_FILE_H
#define SOME_FILE_H

//  entire content of #include file

#endif

以上有时称为包含保护宏.

The above is sometimes referred to as an include guard macro.

在 Objective-C 中,如果您 #import 一个文件,编译器会执行检查以确保它尚未被导入.因此,通常会省略警卫.因此,如果您#include 一个应该被#import 编辑的文件,则不会进行任何检查,有时您会得到重复的定义.

In Objective-C, if you #import a file, a check is performed by the compiler to make sure it has not already been imported. Consequently the guards are usually omitted. So if you #include a file that was supposed to be #imported, neither check will be done and you will sometimes get duplicate definitions.

这篇关于类“test_coredataAppDelegate"的重复接口声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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