将项目从类集合转换为 .dylib 的过程?

发布于 2024-09-30 13:00:29 字数 1261 浏览 8 评论 0 原文

我已经在一个宠物项目上工作了几个星期,并开始认为它可能会被我自己和一些朋友使用。目前,它实际上只是 XCode 项目中的一堆 Objective-C 类,其中有一个我用来测试各种功能的 main() 。如果我将它打包为 .dylib 文件,那么在项目中使用这个库似乎是最简单的。正如我在其他语言中发现的那样,事后才这样做是一件令人讨厌的事情,理想情况下应该将其外包给最低层。 :)

我对 Objective-C/Xcode 世界非常陌生,但根据 Apple 的 “动态库编程主题”,我的印象是,这实际上只是将我的接口文件重新调整为以下格式的问题:(

@protocol Person
- (void)setName:(NSString*)name;
- (NSString*)name;
@end

@interface Person : NSObject <Person> {
    @private
NSString* _person_name;
}
@end

摘自引用的 Apple 文档)。

其中:我正在定义一个协议,其中包含我希望包含在 .dylib 中的类的方法,然后定义一个接口,该接口是 NSObject 的子类,实现上述协议并在中声明 ivars这里。

几个问题

我是否可以从协议中省略我不想“导出”到 dylib 的方法?

如果我在 dylib 中有一个类的子类,我是否为该子类创建另一个协议,并使新创建的类的超类实现该协议?例如,如果我对人进行子类化:

@protocol CatPerson
/* any additional methods for CatPerson not in Person */
- (void) protractClaws;
- (void) retractClaws; 
@end

@interface CatPerson : Person <CatPerson> {
    @private
/* any additional ivars for CatPerson not in Person */
NSNumber *clawCount;
}

这可能是一个非常微不足道的问题,但在我咬牙切齿地将所有类移动到 .dylib 之前,我试图弄清楚我需要做的一切。

I've been working on a pet project for a few weeks now, and starting to think that it may get used by myself and a few friends. At present, it's really just a pile of Objective-C classes in an XCode project with a main() I've been using to test various features. Going forward it seems easiest to use this library in projects if I package it up as .dylib file. As I've found with other languages, doing this as an afterthought is a nuisance that ideally is farmed out to the lowest rung. :)

I'm very new to the Objective-C/Xcode world, but according to Apple's "Dynamic Library Programming Topics", I'm under the impression that it's really just a matter of rejigging my interface files to be of the format:

@protocol Person
- (void)setName:(NSString*)name;
- (NSString*)name;
@end

@interface Person : NSObject <Person> {
    @private
NSString* _person_name;
}
@end

(taken from referenced Apple doc).

Where: I'm defining a protocol that contains the methods I wish to include for the classes to be contained in the .dylib, and then defining an interface that subclasses NSObject implementing the aforementioned protocol and declaring ivars in here.

A few questions:

Am I able to omit methods from the protocol that I don't wish to "EXPORT" to the dylib?

If I have subclasses of a class within the dylib, do I create another protocol for the subclass, and make the superclass of the newly created class implement that protocol? For instance, if I were subclassing person:

@protocol CatPerson
/* any additional methods for CatPerson not in Person */
- (void) protractClaws;
- (void) retractClaws; 
@end

@interface CatPerson : Person <CatPerson> {
    @private
/* any additional ivars for CatPerson not in Person */
NSNumber *clawCount;
}

It's likely a very trivial question, but I'm trying to figure out everything I'll need to do before I go thru the gnashing of teeth of moving all the classes to a .dylib.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她比我温柔 2024-10-07 13:00:29

Project->New Target…在出现的面板中选择“dylib”。使其成为当前目标。按住 Control 键并单击组和文件表视图标题,检查“目标成员资格”。选中您想要包含在 dylib 中的文件旁边的复选框。

Project->New Target… select "dylib" in the panel that you get. Make it the current target. control-click on the groups & files tableview header, check "target membership". Check the boxes next to the files you want included in your dylib.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文