Nepedia
Back to Discover
Advanced Reader
💻

Objective-C

technology Maturity 7-9 Next article →

Objective-C is a high-level, general-purpose, object-oriented programming language. It functions as a strict superset of the C programming language. This means any valid C program can also be compiled using an Objective-C compiler. The language is unique because it adds Smalltalk-style messaging to the existing C structure. This combination allows developers to use powerful object-oriented features while maintaining compatibility with older C code. It has played a massive role in the history of modern computing environments.

The core mechanism of Objective-C is a process called message passing. In many other languages, like C++, a programmer calls a method. In those languages, the compiler usually binds the method name to a specific piece of code before the program runs. However, Objective-C uses a different model where the target of a message is resolved at runtime. This means the receiving object itself interprets the message while the program is active. A message is identified by a selector, which is a unique identifier for the message name. This selector is then resolved to a C method pointer, which is the actual implementation of the task.

Because messages are resolved at runtime, the system does not use type checking for them. This provides a high level of flexibility for the programmer. If a message is sent to an object that cannot respond, the system raises an exception. One major advantage of this dynamic approach is that messages can go unimplemented without causing immediate errors. For instance, you can send a message to a collection of objects even if only some of them are expected to respond. This allows for more adaptable and fluid software designs compared to the Simula-style models used in C++.

Objective-C code is organized into two distinct parts: the interface and the implementation. The interface describes what an object can do, while the implementation contains the actual instructions. Developers typically place the interface in a header file, which uses the .h extension. These files act like a formal declaration of a class. They show the class name, its parent class, and its available methods. Within these declarations, plus signs denote class methods, which act on the class itself. Minus signs denote instance methods, which act on a specific instance of that class.

The actual logic of these methods is written in implementation files, which usually end in .m. The .m extension originally stood for "messages." This separation of concerns allows other parts of a program to understand how to interact with an object without needing to see all the complex code inside it. Developers can also use a feature called a category. A category allows a programmer to add new methods to an existing class without changing the original source code. This makes the language highly extensible for large software projects.

The history of Objective-C began in the early 1980s. It was developed primarily by Brad Cox and Tom Love at their company, Productivity Products International. Cox was interested in software reusability and was inspired by the Smalltalk language. However, he knew that backward compatibility with C was essential for engineers. He originally created an Object-Oriented Pre-Compiler to bridge these two worlds. By 1986, Cox published the formal description of the language in his book, "Object-Oriented Programming, An Evolutionary Approach."

The language gained massive popularity through the company NeXT. In 1988, NeXT licensed the language and used it to build the NeXTSTEP operating system. NeXT developed important libraries like the Application Kit and Foundation Kit. When Apple purchased NeXT in 1996, they adopted Objective-C for their new Mac OS X system. It became the standard language for developing macOS and iOS applications through the Cocoa and Cocoa Touch APIs. This era of dominance lasted until 2014, when Apple introduced the Swift language to its developers.

Today, Objective-C remains a significant part of the computing landscape. While Swift is newer, much of the current Cocoa API is still based on OpenStep interface objects. Objective-C can be compiled for any platform supported by the GNU Compiler Collection or LLVM/Clang. This means it is not strictly limited to Apple hardware. Its ability to blend the efficiency of C with the flexibility of Smalltalk continues to make it a foundational tool in the history of software engineering.

721 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.