最新公告
  • 限时8元开通会员,全站免费下载立即加入我们
  • 黑苹果编程_苹果碳编程快速开始

    黑苹果编程

    Preface

    前言

    First Mac

    I’ve never seen this model. I did see this one:

    我从未见过这种模型。 我确实看到了这个:

    Mac

    Few months ago I bought iPhone. Then Mac mini. I made my first applications for this phone. Then, for my Mac… Goodbye, Microsoft?

    几个月前,我买了iPhone。 然后是Mac mini。 我是第一次为这款手机申请的。 然后,对于我的Mac …再见,微软?

    I think I found a very easy way to step in to the world of the Apple programming. In this short article I want to show how to begin, how to make a first Mac OS X program. I’m not going to scare anyone, I will not talk about Objective-C, I will not use Cocoa. These are very amazing things, but it is, obviously, not the easiest start.

    我认为我找到了进入Apple编程世界的非常简单的方法。 在这篇简短的文章中,我想展示如何开始,如何制作第一个

    We all began from the super language – our old and respectful C. From my point of view, it is extremely easy to begin programming for Mac OS X from Carbon – an old procedural 32bit API for developing Mac OS X application.

    我们都是从超级语言(我们古老而又受人尊敬的C语言)开始的。从我的角度来看,从

    Project Hello

    项目你好

    In case you have a Mac and Xcode installed on it, it will take 2 seconds to make a window application on Mac:

    如果您安装了Mac和

    1. Create new project – File menu -> New Project...

    1.创建新项目- 文件菜单-> 新建项目 。

    2. Choose Carbon Application template in the Application section in the New Project wizard and press Choose button (in the bottom-right corner).

    2.在“新建项目”向导的“应用程序”部分中,选择“ Carbon Application”模板,然后按“选择”按钮(在右下角)。

    3. Set the project name and press Save button.

    3.设置项目名称,然后按保存按钮。

    4. Press Build and Go.

    4.按构建并执行 。

    Here are few images illustrating these steps above:

    以下是说明上述步骤的几张图片:

    Xcode. New Project.
    Set project name

    It runs. The window knows how to minimize and maximize itself. The application has the standard Apple menu.

    它运行。 窗口知道如何最小化和最大化自身。 该应用程序具有标准的Apple菜单。

    Application Hello

    Source code

    源代码

    The application source code is in main.c file. Actually, everything from this file can be removed and replaced by the following code:

    应用程序源代码位于

    1. int main (int argc, char* argv[])
    2. {
    3. IBNibRef nibRef;
    4. WindowRef window;
    5. // Create a nib reference to a nib file.
    6. CreateNibReference (CFSTR (“main”), &nibRef);
    7. SetMenuBarFromNib (nibRef, CFSTR(“MenuBar”));
    8. CreateWindowFromNib (nibRef, CFSTR(“MainWindow”), &window);
    9. // Dispose of the nib reference as soon as you don’t need it any more.
    10. DisposeNibReference (nibRef);
    11. // Make the unarchived window visible.
    12. ShowWindow (window);
    13. // Start the event loop. RunApplicationEventLoop is a
    14. // Carbon Event Manager function.
    15. RunApplicationEventLoop ();
    16. return 0;
    17. }

    Now the program is much shorter – one C-style function (as it should be in the procedural language) with few lines of code:

    现在,程序要短得多-一个

    1. Call CreateNibReference function to create the resource object. Call DisposeNibReference in order to release it.

    1.调用

    2. Call SetMenuBarFromNib function in order to set the application menu.

    2.调用

    3. Call CreateWindowFromNib to create the window from the resource.

    3.调用

    4. Call ShowWindow to show the window.

    4.调用

    5. Use RunApplicationEventLoop function to start the application event loop.

    5.使用

    For a test purpose I can comment (or delete) three window related lines and the function will look like:

    为了进行测试,我可以注释(或删除)三个与窗口相关的行,该函数将如下所示:

    1. int main (int argc, char* argv[])
    2. {
    3. IBNibRef nibRef;
    4. CreateNibReference (CFSTR (“main”), &nibRef);
    5. SetMenuBarFromNib (nibRef, CFSTR(“MenuBar”));
    6. DisposeNibReference (nibRef);
    7. RunApplicationEventLoop ();
    8. return 0;
    9. }

    Now this code compiled and launched creates only the menu:

    现在,此代码已编译并启动,仅创建菜单:

    Only menu
    1. int main (int argc, char* argv[])
    2. {
    3. RunApplicationEventLoop ();
    4. return 0;
    5. }
    Default menu

    Conclusion

    结论

    It is a first and trivial experience in the Mac OS X development. But it gives an optimistic feeling, a confidence that the knowledge in C allows to study Mac OS, to make programs for Apple immediately, without long pauses for Objective-C and Cocoa books.

    这是Mac OS X开发中的第一次和琐碎的经历。 但是它给人一种乐观的感觉,一种确信,即使用C的知识可以学习Mac OS,可以立即为Apple编写程序,而无需长时间停顿Objective-C和Cocoa书籍。

    欢迎来到黑苹果乐园,助力于黑粉用上黑苹果。
    黑苹果乐园 » 黑苹果编程_苹果碳编程快速开始

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    站壳网
    一个高级程序员模板开发平台

    发表评论

    • 425会员总数(位)
    • 353资源总数(个)
    • 6本周发布(个)
    • 0 今日发布(个)
    • 574稳定运行(天)

    提供最优质的资源集合

    立即查看 了解详情
    IP Blocking Protection is enabled by IP Address Blocker from LionScripts.com.