Browsing Cocoa with F-Script
Pages: 1, 2
Adding an Entry to the Workspace
You can assign the currently-selected object to a name in your workspace by clicking on the "Name" button, and typing the chosen name in the sheet. This operation is equivalent to the assignment instruction
:= in the F-Script language.
Fig. 3. A sheet asks for the name of the object.
Note: if you hit the button by mistake, pressing the Return key on your keyboard without typing anything will dismiss the sheet.
Browsing All Classes
You can browse the classes linked to the executable from which you are using the F-Script object browser (since F-Script is offered as an embeddable framework, you may want to use it from different applications). To start browsing the classes, just click on the "Classes" button.
Fig. 4. Browsing classes.
You can manipulate classes through the browser in the same way as other objects. This is because Cocoa classes are themselves regular objects. Indeed, each class is itself an instance of another class (called a meta-class) automatically created by the object system, and meta-classes are themselves objects. Since F-Script makes it so easy to browse these different levels, it can be useful to have a clear view of the topology of the Cocoa class system. We illustrate it below, using the Cocoa
NSBox class as example.
Fig. 5. Topology of the Cocoa class system.
A few remarks:
- In this schema, the class of a class is denoted by adding
(meta)to the class name. For instance, the class of the
NSBoxclass is denoted by
- Each object (including classes) in the system is associated with another object (its class) by the "is instance of" relationship. Note that this relationship is not transitive. Within F-Script, you send the
classOrMetaclassmessage to an object in order to get its class.
- The "inherits from" relationship applies at the class level. For most practical purposes, this relationship can be seen as transitive. You can traverse it by sending an object the
NSObject, the root of the class hierarchy, does not inherit from another class. Sending it the
superclassmessage returns nil.
- With Cocoa, the class methods of a class
Aare the instances methods of
- The fact that meta-classes are organized in a hierarchy that is similar to the corresponding classes' hierarchy explains why class methods are inherited.
- The fact that
NSObject (meta)inherits from
NSObjectexplains why instance methods defined for the root class are also class methods.
NSObject (meta)is the class of all the meta-classes in this hierarchy: it is the meta-meta-class.
There are a few classes that you can't use with F-Script, and therefore can't browse. This includes classes not conforming to the
NSObject protocol (like those inheriting from the "old"
Object class), and some special system classes like
Sending the self Message
All Cocoa objects support the
self message. This simply returns the receiver of the message. As with all other messages, it can be sent using the object browser in the way we described. But sending this message is (surprisingly) so useful in the context of the object browser that there is a shortcut, in the form of the "self" button. By clicking on it, you send the
self message to the selected object.
Sending this message is useful for browsing nested collection, and for getting an up-to-date description of an object.
Inspecting the Selected Object
The "inspect" button opens an inspector for the selected object. A generic inspector is provided and some object offer more specific inspectors (by implementing the
inspect method). For instance, inspecting a block will open a code editor for the block.
The object browser provides a handy way to browse collections of objects like
When browsing a collection, the browser not only presents the collection as a whole, but also displays and makes selectable each of the elements in the collection. Thus, you can select the collection itself, or directly select one of its elements.
Fig. 6. Browsing an NSArray of strings.
When browsing nested collections, sending the
self message to an element lets you conveniently delve into nested sub-levels.
The Status Bar
As you move the mouse pointer, the status bar at the base of the browser shows you a more complete description of objects and methods than the one in the columns, which is sometimes limited by the column size.
Fig. 7. The status bar is handy!
Objects displayed in the column of the browser or by the generic inspector can be modified at any time in a number of ways: events, callbacks, sending a message with side effect from the object browser or from the F-Script shell, etc.
It is important to note that the browser doesn't automatically update its display when such modification occurs. However, selecting an object and sending it the
self message or opening the generic inspector on it will let you see an updated description of the object.
Return to the Mac DevCenter.