Introduction to The Objective-C Programming Language

Refenced from : http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html

Introduction to The Objective-C Programming Language

The Objective-C language is a simple computer language designed to enable sophisticated object-oriented programming. Objective-C is defined as a small but powerful set of extensions to the standard ANSI C language. Its additions to C are mostly based on Smalltalk,one of the first object-oriented programming languages. Objective-C isdesigned to give C full object-oriented programming capabilities, andto do so in a simple and straightforward way.

Most object-oriented development environments consist of several parts:

  • An object-oriented programming language

  • A library of objects

  • A suite of development tools

  • A runtime environment

Thisdocument is about the first component of the developmentenvironment—the programming language. It fully describes theObjective-C language, and provides a foundation for learning about thesecond component, the Mac OS X Objective-C applicationframeworks—collectively known as Cocoa. You can start to learn moreabout Cocoa by reading <!-- a target="_top" -->Getting Started with Cocoa<!-- /a-->. The two main development tools you use are Xcode and Interface Builder, described in Xcode Workspace Guide and <!-- a target="_top" -->Interface Builder<!-- /a--> respectively. The runtime environment is described in a separate document, Objective-C Runtime Programming Guide.

Important: Thisdocument describes the version of the Objective-C language released inMac OS X v10.6, which introduces the associative references feature(see “Associative References”). To learn about version 1.0 of the Objective-C language (available in in Mac OS X v10.4 and earlier), read <!-- a target="_top" -->Object Oriented Programming and the Objective-C Programming Language 1.0<!-- /a-->.

Who Should Read This Document

The document is intended for readers who might be interested in:

  • Programming in Objective-C

  • Finding out about the basis for the Cocoa application framework

Thisdocument both introduces the object-oriented model that Objective-C isbased upon and fully documents the language. It concentrates on theObjective-C extensions to C, not on the C language itself.

Becausethis isn’t a document about C, it assumes some prior acquaintance withthat language. However, it doesn’t have to be an extensiveacquaintance. Object-oriented programming in Objective-C issufficiently different from procedural programming in ANSI C that youwon’t be hampered if you’re not an experienced C programmer.

Organization of This Document

This document is divided into several chapters and one appendix.

The following chapters cover all the features Objective-C adds to standard C.

The Apple compilers are based on the compilers of the GNU Compiler Collection.Objective-C syntax is a superset of GNU C/C++ syntax, and theObjective-C compiler works for C, C++ and Objective-C source code. Thecompiler recognizes Objective-C source files by the filename extension .m, just as it recognizes files containing only standard C syntax by filename extension .c. Similarly, the compiler recognizes C++ files that use Objective-C by the extension .mm. Other issues when using Objective-C with C++ are covered in “Using C++ With Objective-C.”

The appendix contains reference material that might be useful for understanding the language:

Conventions

Wherethis document discusses functions, methods, and other programmingelements, it makes special use of computer voice and italic fonts.Computer voice denotes words or characters that are to be takenliterally (typed as they appear). Italic denotes words that representsomething else or can be varied. For example, the syntax:

@interfaceClassName(CategoryName)

means that @interface and the two parentheses are required, but that you can choose the class name and category name.

Where example code is shown, ellipsis points indicates the parts, often substantial parts, that have been omitted:

- (void)encodeWithCoder:(NSCoder *)coder
{
[super encodeWithCoder:coder];
...
}

The conventions used in the reference appendix are described in that appendix.

See Also

If you have never used object-oriented programming to create applications before, you should read Object-Oriented Programming with Objective-C.You should also consider reading it if you have used otherobject-oriented development environments such as C++ and Java, sincethose have many different expectations and conventions fromObjective-C. Object-Oriented Programming with Objective-Cis designed to help you become familiar with object-orienteddevelopment from the perspective of an Objective-C developer. It spellsout some of the implications of object-oriented design and gives you aflavor of what writing an object-oriented program is really like.

Runtime

Objective-C Runtime Programming Guide describes aspects of the Objective-C runtime and how you can use it.

Objective-C Runtime Referencedescribes the data structures and functions of the Objective-C runtimesupport library. Your programs can use these interfaces to interactwith the Objective-C runtime system. For example, you can add classesor methods, or obtain a list of all class definitions for loadedclasses.

Objective-C Release Notes describes some of the changes in the Objective-C runtime in the latest release of Mac OS X.

Memory Management

Objective-C supports two environments for memory management: automatic garbage collection and reference counting:

相关推荐