What’s the difference between Xcode, Objective-C and Cocoa?

前端 未结 3 1200
天涯浪人
天涯浪人 2021-02-01 06:56

This question pops up quite often here, even if just implicitly when users mistag their iOS questions. So, what’s the difference between Xcode, Objective-C and Cocoa?

3条回答
  •  逝去的感伤
    2021-02-01 07:32

    Xcode is the integrated development environment (IDE)—the application—that developers use to write software for iOS and/or OS X. It includes the editor, the build system (determining what to build to produce the desired target), and quite a few other things.

    Objective-C is the main language that developers write such software in. They may write bits of it in pure C, use C++ or combine it with Objective-C (producing Objective-C++), or write some or all of the program in another language entirely, such as MacRuby, Java (with j2objc), or C# (with MonoTouch).

    Xcode includes the Clang compiler, which turns code written in Objective-C, C, and a few other languages into executable code. Most error messages come from Clang, and Xcode relies heavily on it for search indexing, syntax highlighting, and name completion of Objective-C code.

    Cocoa and Cocoa Touch are application frameworks. Each one is a suite of many individual frameworks (libraries stored in folders named blahblah.framework), such as:

    • Foundation (both): General object-oriented utilities, including NSString, NSURL, NSFileManager, etc.
      • Core Foundation (both): Mostly the same thing, but different, mainly in having a C-based API rather than Objective-C
    • Application Kit (Mac): Application and windowing framework
    • UIKit (iOS): Application and windowing framework
    • Core Graphics (both): Drawing
    • Core Animation (both): Sprite-management and animation framework

    (and many, many more where they came from, especially on the Mac)

    So:

    • You can use a framework besides Cocoa or Cocoa Touch, but you'll have to have some Cocoa/Cocoa Touch code, at some level, in order for your application to talk to the system, receive events, draw, etc. Frameworks that specifically target Mac and/or iOS will include the relevant wrappers for you, at varying levels of quality.
    • You can use a language besides Objective-C, but you'll have lots of syntactic awkwardness, as most of Cocoa and Cocoa Touch are designed for Objective-C's unique syntactic features (particularly selectors).
    • You can use an editor besides Xcode, and you can even use a build system besides Xcode (such as make), but Apple's App Stores expect apps built a particular way (especially with regard to code signing), so unless you're not targeting the App Stores, any other build system has to replicate what Xcode does or risk its users getting rejections.

提交回复
热议问题