Xcode添加C语言代码出错

  项目中需要用C语言实现一部分功能,新建C语言文件报错,错误如下:

  检查C语言代码,并没有什么写的不对的地方。查看错误信息列表,发现和自己代码相关的错误在.pch文件中。新建pch文件的时候,默认的是为整个项目代码引入UIkit、Foundation、CoreData框架,但是C语言文件中引入这些文件就会出错。所以这个时候,我们把C语言文件隔离出来。

  旧代码:

#ifndef iRun_Prefix_pch
#define iRun_Prefix_pch

// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "Masonry.h"

#endif /* iRun_Prefix_pch */

  新代码:

#ifdef __OBJC__
#define iRun_Prefix_pch

// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "Masonry.h"

#endif /* iRun_Prefix_pch */

  以上。

posted @ 2016-02-29 16:45  i左撇子  阅读(450)  评论(0编辑  收藏  举报