1 / 21

Mac OS X Programming

Mac OS X Programming. Using Cocoa with Objective-C. © 2003 Greg Howell (greg@diversionary.net). What is covered:. Cocoa application development Objective-C as the primary programming language Jaguar (10.2) Developer Tools although most comments apply to Xcode (Panther). What is not covered:.

london
Download Presentation

Mac OS X Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mac OS X Programming Using Cocoa with Objective-C © 2003 Greg Howell (greg@diversionary.net)

  2. What is covered: • Cocoa application development • Objective-C as the primary programming language • Jaguar (10.2) Developer Tools although most comments apply to Xcode (Panther)

  3. What is not covered: • Carbon application programming • Porting Unix applications to Mac OS X • Java programming

  4. The Apple Developer Tools • Project Builder (or Xcode under Mac OS X 10.3) • IDE (code editor and project browser) • Front end for GCC • Interface Builder • Used for GUI construction • Used to link UI elements to methods in code • Both tools have a significant NeXT heritage

  5. Project Builder & Xcode • Used to edit source code • Edit source code • Set project properties • Set compilation options • Set properties of compiled application

  6. Interface Builder • Used to edit the .nib file • Can access this through Project Builder or Xcode • The .nib file defines what objects exist at startup in the application • The .nib file specifies the links between user interface elements and methods in objects

  7. Mac OS X Environment

  8. Cocoa • Set of OO APIs derived from NeXT technologies • The NS prefix of most Cocoa objects stands for NeXTSTEP (seems to have followed Mr. Jobs) • Framework for building applications • Set of objects that mediate between the program and the OS • Used to take advantage of Carbon features • Most of the iApps are built on top of Cocoa • iPhoto, iDVD, iChat, Mail

  9. Objective-C Programming • General syntax • .m and .h files • General project structure • How a Cocoa application starts up • Using other languages

  10. Objective-C • An extension of ANSI C • Programmer can choose to implement features as classes (in an OO manner) or use standard C methods such as structures • Main extensions are message passing and the syntax for defining classes and methods • The extensions are straightforward, the OO design principles are sometimes hard to comprehend

  11. Objective-C: General Syntax anObject = [NSObject alloc]; Returned Value Message Receiver Method Name

  12. Objective-C: .m & .h files • .m files • Objective-C implementation file for a class • .h files • Header files for .m files • Define the interface to the class • Can also use .h files as standard C style header file for macros, declarations etc.

  13. Objective-C: Project Structure • main.m • Contains the main() function • Objective-C class and interface files • Usually one application controller class • Other classes as required • Other C header files (if required) • Other C source files (if required)

  14. Objective-C: Typical Start Up • main() function in main.m calls NSApplication() • This opens the .nib file for the application • The .nib file defines what objects are created • The classes which define these objects can have a startup method (called awakeFromNib())

  15. Objective-C & Other Languages • Just add the functions into the .m implementation file and call it wherever it is required • I used a Pascal call-back routine in the screen reader to operate TTS

  16. Sources of Documentation • General programming websites • Apple’s Developer website (in particular the sample code section) • Books (O’Reilly and others) • Documentation on hard drive installed with Developer tools (both documentation and sample code)

  17. Strings • There are two types of strings I encountered: • Cocoa strings (string objects) • “C” style strings (character arrays) • Cocoa String Objects • NSString (standard string object) • NSMutableString (string object that is able to be manipulated) • Straightfoward to convert between the two

  18. Arrays • NSArray object

  19. Speech Synthesis • Need to create a new speech channel • If you use the standard OS speech channel you can generate speech but you have no control over it • You can specify TTS properties when you create a speech channel (or just use the system defaults) • Once created it is easy to generate speech • The TTS engine runs as a separate process (leaving the application to do what it wants) • It is interruptible (no queue) • You need a call-back routine to determine when the TTS engine finishes generating speech from the string you sent it

  20. Putting Together an Application • Adding an icon to the application • About Box tricks • Can use a text, RTF or image file • Changing version numbers • There are two places to alter version numbers • Distributing an application • Disk image (.dmg file) • Installer package

  21. Any Questions?

More Related