简体   繁体   English

将应用程序从碳转移到可可

[英]migrating an application from carbon to cocoa

I am working on an application in which I need to migrate the whole code of it from carbon to cocoa.I have experience in programming of C,C++,python and Java during my college time and internship but have never touched objective C or have done any programming for Mac(Carbon and Cocoa) before this. 我正在开发一个应用程序,我需要将它的整个代码从carbon迁移到cocoa。我在大学时间和实习期间有C,C ++,python和Java编程经验,但从未接触过目标C或已完成在此之前为Mac(Carbon和Cocoa)编程。

So Can you please suggest me some sources to start with, also how should I go about the whole migration ? 那么你能否请一些资料来建议我,我该如何进行整个迁移呢?

After researching on net I have found that most the people have suggested following books 在对网络进行研究后,我发现大多数人都建议使用以下书籍

Cocoa Programming for Mac® OS X, Third Edition by Aaron Hillegass 适用于Mac®OSX的Cocoa编程,第三版由Aaron Hillegass编写

Programming in Objective C - Stephen Kochan 目标C中的编程 - Stephen Kochan

I have got both these books. 我有这两本书。

Should I read them first and then should start with the code change? 我应该首先阅读它们然后应该从代码更改开始吗? (it will take some time to read both of these) (这两个方面都需要一些时间)

OR 要么

after having a decent fimiliarity with Obj C and Cocoa, should I directly get started with code migration? 在对Obj C和Cocoa有一定的了解之后,我应该直接开始代码迁移吗?

Also, 也,

since I don't know carbon , what should I refer to learn carbon to have sufficient knowledge to migrate the carbon code to cocoa? 既然我不知道碳,那么我应该提到学习碳有足够的知识将碳代码迁移到可可?

First, learn Carbon so you can read the program and understand how it's currently implemented. 首先,学习Carbon,这样您就可以阅读该程序并了解它当前的实现方式。

Install the Legacy documentation set in Xcode to gain access to the Carbon guides. 在Xcode中安装Legacy文档集以访问Carbon指南。 You'll want to read the Carbon Overview , then Getting Started with Carbon , then everything that Getting Started links to. 您需要阅读Carbon概述 ,然后阅读Carbon 入门 ,然后阅读“入门”链接的所有内容。 You'll also need to learn Core Foundation, which some of the more modern parts of Carbon use; 你还需要学习Core Foundation,这是Carbon使用的一些更现代的部分; read Core Foundation Design Concepts and the Memory Management Programming Guide for Core Foundation . 阅读Core Foundation Design ConceptsCore Foundation内存管理编程指南

Then, learn Cocoa. 然后,学习Cocoa。

I didn't learn by the Hillegass book, but a lot of people swear by it. 我没有通过希勒盖斯的书来学习,但很多人都发誓。 My current favorite Cocoa book is “Cocoa and Objective-C: Up and Running” by Scott Stevenson . 我目前最喜欢的可可书是斯科特史蒂文森的“Cocoa and Objective-C:Up and Running” The way I learned Cocoa was using Apple's own docs. 我学习Cocoa的方式是使用Apple自己的文档。 Start with The Objective-C Programming Language , the Cocoa Fundamentals Guide , and the Memory Management Programming Guide for Cocoa . Objective-C编程语言Cocoa基础指南Cocoa内存管理编程指南开始 Much of the last document will seem really familiar, but skip nothing. 最后一篇文章的大部分内容似乎都很熟悉,但没有任何内容。 Read every one of those guides from beginning to end and all the way through. 从头到尾阅读每一个指南并一直阅读。

Once you've learned Cocoa's general concepts, you can move on to more application-specific material. 一旦学习了Cocoa的一般概念,就可以继续学习更多特定于应用程序的材料。 Start with the Application Architecture Overview and most of what that document links to. 应用程序体系结构概述开始,以及该文档链接的大部分内容。 The Cocoa Guides list has the full list of guides. 可可指南列表包含完整的指南列表。

Down the road, you'll also need to make the application compatible with 64-bit mode. 在路上,您还需要使应用程序与64位模式兼容。 If you still have any Carbon code by that point, you'll need to read the 64-bit Guide for Carbon Developers ; 如果到那时你仍然有任何碳代码,你需要阅读64位碳开发者指南 ; either way, you'll also need the general 64-bit Transition Guide and the 64-bit Transition Guide for Cocoa . 无论哪种方式,您还需要通用的64位转换指南64位的Cocoa转换指南

I am working on this process myself right now, and it's a fairly complex undertaking for a full document-based application that uses a few frameworks. 我现在正在研究这个过程,对于使用一些框架的完整的基于文档的应用程序来说,这是一项相当复杂的工作。 My Carbon app has dozens of menu items, the interface is built with Carbon Nibs and implemented using Carbon event hooks. 我的Carbon应用程序有许多菜单项,界面使用Carbon Nibs构建,并使用Carbon事件挂钩实现。 The programming language is C++. 编程语言是C ++。 Going back in history, the original Mac classic version was implemented in straight C, so there's a little bit of legacy from that era too. 回顾历史,最初的Mac经典版本是在C语言中实现的,所以这个时代也有一些遗产。 Resource-based PICS for example! 例如基于资源的PICS!

There are several approaches one can take, so it depends on your particular situation how to proceed. 有几种方法可以采取,所以这取决于您的具体情况如何进行。 In my case I decided to start with a bare Cocoa document-based project and start building the document loading code, because the hooks for that are already in place in the empty project. 在我的情况下,我决定从一个基于Cocoa文档的裸项目开始,并开始构建文档加载代码,因为它的钩子已经在空项目中已经存在。 This seems like a good place to start for me, because it gets me into the mode of working with Cocoa and thinking about the app in terms of smaller pieces. 这似乎是一个适合我的好地方,因为它让我进入了与Cocoa合作的模式,并考虑到小块的应用程序。

You really have to take a methodical approach and look at what your app depends on in Carbon versus which parts of your app are independent - for instance your abstract classes. 你必须采取一种有条不紊的方法,看看你的应用程序在Carbon中所依赖的内容与应用程序的哪些部分是独立的 - 例如你的抽象类。 If your app is in C++ there may be some pitfalls with converting over to pure Objective-C. 如果您的应用程序使用C ++,那么转换为纯Objective-C可能会有一些陷阱。 Operator overrides can be tricky to notice, for example. 例如,运算符覆盖可能很难注意到。

You can mix C++ with Objective-C, as described in Apple's Carbon-Cocoa Integration Guide and around the web you can find plenty of C++ wrappers for Cocoa foundation objects like NSStrings . 您可以将C ++与Objective-C混合使用,如Apple的Carbon-Cocoa集成指南中所述 ,在Web上,您可以找到大量用于Cocoa 基础对象(如NSStrings)的C ++包装器。 So if you already have C++ classes that wrap CFString, these can come in handy. 因此,如果您已经拥有包装CFString的C ++类,这些可以派上用场。

Generally-speaking, you can leave your data storage just as it is. 一般来说,您可以保留数据存储空间。 If you use malloc() and calloc() to make a linked list of structs, there's no special reason to move over to an NSArray. 如果使用malloc()和calloc()来创建结构的链接列表,则没有特殊的理由转移到NSArray。 You won't get better performance. 你不会得到更好的表现。 The real change comes in the interfaces, the way you call and access that data from other objects. 真正的变化来自接口,您调用和访问其他对象的数据的方式。 If you decide to mix C++ and Objective-C objects in the same app it helps to encapsulate as much as possible. 如果您决定在同一个应用程序中混合C ++和Objective-C对象,则有助于尽可能地封装。 That is, as much as possible make your abstract C++ classes only refer to their own data and that of other C++ objects. 也就是说,尽可能使您的抽象C ++类仅引用自己的数据和其他C ++对象的数据。 Eventually this will make it easier to transition them to Objective-C. 最终,这将使它们更容易转换为Objective-C。

If you're transitioning from one event model to another or from Carbon port-based imaging to Cocoa's views-based imaging, it's probably best to start with a fresh Objective-C app and bring over your model classes first. 如果您正在从一个事件模型转换到另一个事件模型,或者从基于Carbon端口的映像转换到Cocoa基于视图的映像,那么最好先从一个新的Objective-C应用程序开始,然后首先引入您的模型类。 Add some test functions to make sure they all work within the new language. 添加一些测试函数以确保它们都在新语言中工作。 If your app is anything like mine (old) then it probably needs to display some things larger, and to have more polish in the interface. 如果您的应用程序类似于我的(旧),则可能需要显示更大的内容,并在界面中进行更多润色。 This is a good time to rebuild those parts piece-by-piece. 这是一个一块一块地重建这些零件的好时机。

There's definitely no great shortcut. 肯定没有很好的捷径。 The PDF linked above is the best document I've found on the topic. 上面链接的PDF是我在该主题上找到的最佳文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM