英文:
Creating iOS framework with Objective-C
问题
我在iOS上创建框架时遇到了一些问题。
我创建了一个新项目(名为Logger)并选择了“Framework”选项。
然后,Xcode创建了文件夹结构,其中包括Logger.h
,但没有创建Logger.m
。
接下来,我创建了一个名为AppLogger
的新Cocoa Touch文件,并添加了一些基本逻辑。
我在Logger.h
中导入了AppLogger.h
文件,像这样:
#import <Logger/AppLogger.h>
我也尝试过这样写:
#import "Logger/AppLogger.h"
但是它给我一个错误:
'Logger/AppLogger.h'文件未找到
我不明白我的设置有什么问题。
附上了我的项目结构的图像。
英文:
I have some trouble creating a framework for iOS.
I created a new project (called Logger) and selected the Framework
option.
Then, Xcode created the folder structure and it had a few files including Logger.h
, but no Logger.m
was created.
Then, I have created new Cocoa Touch file called AppLogger
and added some basic logic to it.
I imported the AppLoger.h
file in my Logger.h
like this:
#import <Logger/AppLoger>
I also tried it like this:
#import "Logger/AppLoger"
But it gives me an error:
'Logger/AppLogger.h' file not found
I don't understand what the problem is with my setup.
Attached is also an image of my project structure.
答案1
得分: 3
我刚刚在几天前经历了这个问题。您添加到主框架头文件的头文件应该是您框架的公共头文件。这意味着您需要将头文件标记为公共(而不是项目或私有)。
以下截图显示了您需要执行的操作:
- 选择应该是公共的头文件。
- 确保检查器面板显示在Xcode右侧。
- 选择“文件检查器”选项卡。
- 在“目标成员资格”下,确保头文件标记为“公共”。它默认为“项目”。
完成这些步骤后,您可以在Logger.h文件中添加以下行#import <Logger/AppLogger.h>
。
对于项目中的其他.h文件,您需要按照相同的步骤操作,但选择“项目”(而不是“公共”或“私有”)。并使用“正常”的导入方式。例如,在AppLogger.m中,您可能需要导入BaseLog.h。使用以下方式:
#import "BaseLog.h"
在将BaseLog.h设置为“项目”目标成员资格之后。
英文:
I just went through this myself a few days ago. The header files that you add to the main framework header are meant to be the public headers of your framework. This means you need to mark the header as being public (versus project or private).
The following screenshot shows what you need to do:
- Select the header that should be public.
- Ensure the Inspectors pane is being shown on the right side of Xcode.
- Select the File Inspector tab.
- Under Target Membership, ensure the header is marked as Public. It defaults to Project.
With those steps complete you can add the #import <Logger/AppLogger.h>
line to the Logger.h file.
For other .h files in the project, you need to follow the same steps but select "Project" (not Public or Private). And use a "normal" import. For example, in AppLogger.m you might need to import BaseLog.h. Use:
#import "BaseLog.h"
after setting BaseLog.h was a target membership of "Project".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论