This issue occurs on IRC. For ov developers, it is often possible to mention the issue of OS X programming. We often mention the words related to carbon, cocoa, and objective-C. Some friends have also begun to ask, what is carbon? What is cocoa? What should I do if I want to develop a program on OS X?
This article first answers two questions: what is carbon and cocoa? Then, the difference between the two is also obvious.
Simply put, carbon and cocoa are both Mac OS x APIs, that is, program tracing required for programming on OS X. It's like
Use the MFC or Win32 SDK on Windows, and have QT/GTK on X-window.
Why is there a "two sets" program? People familiar with windows programming may already have guessed: "Oh, a set of" low-cost "programs, such as Win32 sdks in C ++, A set of high-performance program libraries, such as C ++ runtime MFC, right? 」
The answer is not completely correct. Carbon and cocoa are two APIs with different historical backgrounds. Because I started using MAC from OS X.
Too many historical backgrounds may be exposed. In the English version of Wikipedia, there are two Irrelevant articles (Wikipedia: Carbon
/Cocoa
) Introduce the stories of these two sets of APIs. If you are interested, you can go to zookeeper.
However, I still have a limited understanding of the background of carbon and cocoa. Carbon is the API architecture proposed by Apple since the end of the OS 9 era to help developers migrate program to OS X. At that time, there was a program named carbonize, which meant to put the 9-Generation OS program on carbon and re-compile it into OS X. Most of the large applications on OS X come from this line, such as Adobe
The series of programs, Word and Excel of microservices, etc. are all carbon program applications.
Cocoa is a little more colorful than Alipay. In the simplest and simplest way: cocoa is the API of the nextstep operating system of that year. Apple decided to introduce the objective-C APIs in the production system based on Mach-BSD under nextstep later in the year. Cocoa "is" nextstep "is not too straightforward because all cocoa APIs start with" ns. NS is the release sequence of nextstep. Recently used apps, such as safari, textedit, and cute adium, are all made of cocoa labels.
So what is the relationship between carbon and cocoa? Where is the difference? In some respects, carbon is indeed a low-cost API, while cocoa
There are indeed a lot of practical work, and the bottom layer is to call carbon. However, even the hacker has the carbon call to cocoa.
As far as OS X is being developed, carbon and cocoa are both being developed. Carbon is still mainly used by C/C ++ programmers.
Cocoa is mainly used by programmers who use objective-C/objective-C ++/Java (no response, cocoa claims to have good Java support. Since there are still a relatively large number of weight monitoring bodies using carbon on Mac, Apple cannot declare carbon fade out at a time.
Therefore, it is better to say that carbon/cocoa are two "Parallel" APIs than they are mutually independent APIs. Apple's search function API (and the spotlight technology that will be imported into 10.4 Tiger) is only available for carbon's c API. As for Apple's well-known WebKit and textview (allowing you to upload a set of fully functional Uploader/Uploader in the 15th minute period), only the cocoa kit is available.
Introduce it here, just a few routines. Let's talk about the string operation. The following code shows how to create a string in carbon:
Char * STR = "Hello, world! "; // We want to provide the constructed cfstringref cfstr = cfstringcreatewithcstring (null, STR, kcfstringencodingutf8); // use the string... cfrelease (cfstr); // release the created string token.
For cocoa, this program can be used as follows:
Char * STR = "Hello, world! "; Nsstring * nsstr = [[nsstring alloc] initwithcstring: Str]; // use the string [nsstr release];
Of course, this is the most simple operation, so it cannot be seen where the difference between carbon/cocoa is. The following line of code is to introduce the content of the http://www.google.com into a string:
NSString* s = [NSString stringWithContentsOfURL: [NSURL URLWithString: @"http://www.google.com"]];
Well, carbon won't be able to handle this. However, the magic of Carbon/cocoa is that the core primitive objects, such as strings and character columns, can interact with each other! For example, if a carbon API requires the cfstringref parameter, you can directly overwrite the nsstring * parameter. If a cocoa API requires nsarray * records, you can directly issue the cfarrayref of carbon to it. So, if you have to write a carbon program to catch it on the internet, you can first use the above program to capture the website (I have not used the objective-C program wget tool, as long as the above line is used, is the program finished ?), Then, use nsstring * s as cfstringref. If you want to print the volume content, you can also do this:
printf ("%s/n", [s UTF8String]);
Similar to nsstring/cfstringref, Apple regards it as toll-free
Bridging), very high.
Next, there are two common questions. The first question is, which one should I choose to start? This is the issue I have developed with OV. I will say that it starts directly from cocoa! What can cocoa say about it is a newer design, and it is also the application interface of bottom-end objects. Various new programming tools on Apple Mac OS X, especially interface builder, are tailor-made for cocoa. What's more, cocoa supports non-disruptive Java, and can also call applescript on a single basis. Cocoa is the first choice for developing OS X applications.
But the question is, do I have to learn objective-C? The answer to this question is: yes, but I can learn it soon. In general, if you develop GUI programs, most of them use interface builder to pull the selections and conversation boxes, and the objective-C, the actual size is not too large. In most data scenarios, you only need to know how to call the method of a cocoa object.
In fact, objective-C should be very handy for people who have already learned C ++/C #/Java. In addition, Apple designed objective-C ++ to make programming easier for C ++ programmers. Simply put, C ++ can call objective-C objects or call C ++ through objective-C.
Objective-C with C ++ is a useful tool. At the beginning of openvanilla's development, the OS X dependency program of the plugin is still based on carbon. However, in the initial stage, we quickly developed the routing mode, so we used the C ++/Cocoa/carbon mixed mode, that is, objective-C ++ is used to call carbon and cocoa. Objective-C ++ was developed with a very rapid prototype. One night, we created a prototype of the "Easy-to-use model group, after a while, I spent another evening working on the prototype of "White-text injection", all of which were completed using objective-C ++. Of course, people who have passed the program know that the prototype and the actual version can fully meet the requirements, and there is a large gap between them, I just want to explain how objective-C ++ helps programming. Of course, there are two worlds around the world. Currently, objective-C ++ is only available on the Apple OS X platform (objective-C is based on GCC and gnustep, ), and more cocoa is used, it is very easy to use other APIs, because it is really too simple and easy to use.
Cocoa does not only support objective-C, objective-C ++, and Java. Cocoa already has a python interface, and Perl also has camelbones
This set of program APIs can be used.
Simply put, cocoa will bring people online. I always think that Apple should change its name to cocaine in a future version) yes.