Cocoabox 1 1 – Store Unlimited Cocoaobjective C Snippets

Posted on  by

THE COCOA EXCHANGE™ is our marketplace where cocoa and chocolate come to life in exclusive, innovative ways. And Cocoa Box was created to celebrate and explore delicious new world of craft chocolate. We hope to educate the community on craft chocolate, and in the process support chocolatiers and cocoa farmers. Calling the base class initializer and deallocator. When a class is derived from some other class (as the MyClass was derived from NSObject), the instances created from it are not only instances of the derived class, but also instances of the base class.This is called the is-a relation. A derived class is an extension of the base class: it can do more than the base class, but it can do.

< Cocoa Programming
Cocoa Programming
First Steps Objective-C basics Memory Management Foundation Kit Application Kit Web Kit

Objective-C is the native language of Cocoa applications. It is an object-oriented superset of ANSI C, allowing the developer to include 'plain C' statements and code into the program. Any ANSI C program is a valid Objective-C program.

NSObject[edit]

The Objective-C used in Cocoa is a bit different from 'plain' Objective-C, because of the Cocoa runtime system which defines a new root class, NSObject. All Cocoa objects should be descendants of NSObject in order to gain from its improved memory management model.

NSObject is defined in the header <Foundation/NSObject.h>.

The NSObject life cycle[edit]

To create an NSObject, send its class either analloc or a new message:

Although 'new' and 'alloc followed by init' methods appear to be identical, Apple documentation seems to give preference to the latter method.This gives developers the ability to override alloc or init separately to achieve a certain result, if necessary.

Note that initializing an object may sometimes fail: for example afile containing the initialization data may be unavailable. In thatcase, init will return nil. Therefore, it isalways necessary to check the return value of init beforeusing the object!

After an object has been initialized, it is ready for use. To use an object,send it messages:

If the object understands the message, it will react to it. Otherwise,a trap is generated.

When an object is no longer used, it must be released. To release an object, send it a release message.

This will lead to the destruction of the object (unless it's still in use somewhere else, see Cocoa memory management for details).

When an object is about to be destroyed, it will receive a dealloc message. If the object has reserved any resources, it should release them now.

Extending NSObject[edit]

All classes in an Cocoa/Objective-C application should be derivatives of NSObject. Thus, when defining a new class you should follow some basic rules:

  • Derive from NSObject:
  • Either directly or from a derivative
  • Define initializer & deallocator
  • Call base class initializer & deallocator

Deriving from NSObject[edit]

To create your class as a subclass of NSObject, define it as follows (in the interface definition file 'MyClass.h'):

Defining initializer and deallocator[edit]

An initializer is a method that initializes an object. In Cocoa, the initializer for NSObject is called init. The init method for NSObject does not know about user-defined classes and cannot therefore initialize their instances properly. Thus, it is essential to write an initializer method for your class. If the initialization does not require any parameters, the method to define is called init (i.e., you should override the base class initializer). This makes it possible to create instances of your class by using the new class method derived from NSObject:

The above code creates a new instance of MyClass. Since MyClass has no methods called alloc or init, the messages are automatically sent to its base class.

To override the initializer for your class, optionally define it in the interface file:

and implement it in the.m file:

Cocoa Box 1 1 – Store Unlimited Cocoa Objective C Snippets Youtube

Cocoabox 1 1 – Store Unlimited Cocoaobjective C Snippets

If the initialization requires additional parameters, you should define an initializer like initWithParam:, for example

Cocoa Box 1 1 – Store Unlimited Cocoa Objective C Snippets Tutorial

Even then, it is often advisable to define a 'default' initializer that calls your initWithXXX method with suitable default parameters:

A deallocator is a method that is responsible to release all resources an object holds. The deallocator is called before an object is released, thus making sure everything gets cleaned up properly. In Cocoa, the deallocator method is dealloc. Every class that holds any resources should define a dealloc method. For example:

Calling the base class initializer and deallocator[edit]

When a class is derived from some other class (as the MyClass was derived from NSObject), the instances created from it are not only instances of the derived class, but also instances of the base class. This is called the is-a relation. A derived class is an extension of the base class: it can do more than the base class, but it can do everything the base class can. Therefore, objects of a derived class always contain everything that objects of the base class contain. If an NSObject contains a retain count member variable, then also MyClass objects will contain it. Thus, the 'base class part' of a derived object needs to be initialized and deallocated when initializing and deallocating the derived object.

To initialize the base class part of an object write

to the very beginning of the initializer of your class. To deallocate the base class part of the object write

to the very end of the deallocator of your class.

More information[edit]

For more information on Objective-C in Cocoa, see

  • Objective-C Programming for general information on Objective-C
  • Objective-C GNUstep Base Programming Manual for specific information on Objective-C in Cocoa/GNUstep.
Retrieved from 'https://en.wikibooks.org/w/index.php?title=Cocoa_Programming/Objective-C_basics&oldid=3677661'
Cocoa
  • Cocoa bean processing
  • Cocoa bean products
    • Cocoa powders
    • Chocolate products
Please select which sections you would like to print:

Our editors will review what you’ve submitted and determine whether to revise the article.

Join Britannica's Publishing Partner ProgramCocoabox 1 1 – Store Unlimited Cocoaobjective C Snippets and our community of experts to gain a global audience for your work! L. Russell CookSee All Contributors
President, Chocolate and Confectionery Division, W.R. Grace & Company, New York City, 1965–73. Author of Chocolate Production and Use.
Alternative Title: cocoa powder

Cocoa, highly concentrated powder made from chocolate liquor—a paste prepared from cocoa beans, the fruit of the cacao—and used in beverages and as a flavouring ingredient. Cocoa is the key ingredient in chocolate and chocolate confections.

Chocolate

The cocoa bean is the seed of the cacao tree (Theobroma cacao), a tropical plantindigenous to the equatorial regions of the Americas. From the processed cocoa bean comes the fluid paste, or liquor, from which cocoa powder and chocolate are made. Chocolate is sold directly to the consumer as solid bars of eating chocolate, as packaged cocoa, and as baking chocolate. It is also used by confectioners as coating for candy bars and boxed or bulk chocolates, by bakery product manufacturers and bakers as coating for many types of cookies and cakes, and by ice-cream companies as coating for frozen novelties. Cocoa powders, chocolate liquor, and blends of the two are used in bulk to flavour various food products and to provide the flavours in such “chocolate” products as syrups, toppings, chocolate milk, prepared cake mixes, and pharmaceuticals.

History of use

Cacao residues on pottery in Ecuador suggest that the plant was consumed by humans as early as 5,000 years ago. The tree was likely domesticated in the upper Amazon region and then spread northward. It was widely cultivated more than 3,000 years ago by the Maya, Toltec, and Aztec peoples, who prepared a beverage from the bean (sometimes using it as a ceremonial drink) and also used the bean as a currency.

Christopher Columbus took cocoa beans to Spain after his fourth voyage in 1502, and the Spanish conquistadores, arriving in Mexico in 1519, were introduced to a chocolate beverage by the Aztec. The Aztec beverage was made from sun-dried shelled beans, probably fermented in their pods. The broken kernels, or nibs, were roasted in earthen pots and then ground to a paste in a concave stone, called a metate, over a small fire. Vanilla and various spices and herbs were added, and corn (maize) was sometimes used to produce milder flavour. The paste, formed into small cakes, was cooled and hardened on shiny leaves placed under a tree. The cakes were broken up, mixed with hot water, and beaten to foamy consistency with a small wooden beater, a molinet, producing the beverage called xocoatl (from Nahuatl words meaning “bitter water”).

Get exclusive access to content from our 1768 First Edition with your subscription. Subscribe today

Too bitter for European taste, the mixture was sweetened with sugar when introduced to the Spanish court. Although Spain guarded the secret of its xocoatl beverage for almost 100 years, it reached Italy in 1606 and became popular in France with the marriage of the Spanish princess Maria Theresa to Louis XIV in 1660. In 1657 a Frenchman opened a London shop, selling solid chocolate to be made into the beverage, and chocolate houses, selling the hot beverage, soon appeared throughout Europe. By 1765 chocolate manufacture had begun in the American colonies at Dorchester, in Massachusetts, using cocoa beans from the West Indies.

In 1828 C.J. van Houten of the Netherlands patented a process for obtaining “chocolate powder” by pressing much of the cocoa butter from ground and roasted cocoa beans. In 1847 the English firm of Fry and Sons combined cocoa butter, a by-product of the pressing, with chocolate liquor and sugar to produce eating chocolate, and in 1876 Daniel Peter of Switzerland added dried milk to make milk chocolate. The proliferation of flavoured, solid, and coated chocolate foods rapidly followed.

Starting in the Americas in an area stretching from southern Mexico to the northern countries of South America, commercial cacao cultivation spread around the world to areas within 20° of the Equator where rainfall, temperatures, and soil conditions were suitable for its growth.

Cocoa bean processing

Harvesting

Harvesting of cocoa beans can proceed all year, but the bulk of the crop is gathered in two flush periods occurring from October to February and from May to August. The ripe seed pods are cut from the trees and split open with machetes. The beans, removed from the pods with their surrounding pulp, are accumulated in leaf-covered heaps, in leaf-lined holes dug in the ground, or in large shallow boxes having perforated bottoms to provide for drainage.

Quick Facts
key people
related topics