Cross Platform Objective C Development Using Gn Ustep

3,339 views
3,237 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,339
On SlideShare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
45
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Cross Platform Objective C Development Using Gn Ustep

  1. 2. What is Objective-C ? <ul><li>it is a programming language
  2. 3. it is a strict superset of C </li><ul><ul><li>it is C with some new additional constructs
  3. 4. C code compiles as Objective-C code
  4. 5. C libraries can be linked and used natively from Objective-C </li></ul></ul><li>it adds Object-Oriented features to C </li><ul><ul><li>Defining classes
  5. 6. Implementing methods
  6. 7. Instantiating classes and objects
  7. 8. Invoking class and object methods
  8. 9. Protocols, categories, selectors, forwarding </li></ul></ul></ul>
  9. 10. Example of Objective-C Code
  10. 11. Why is Objective-C so special ? <ul><li>It is compatible with C libraries
  11. 12. Is is a simple extension of C
  12. 13. It is a hybrid between C and Smalltalk </li><ul><ul><li>It can be as fast as raw C if you avoid the object-oriented extensions
  13. 14. It can be as high-level and flexible as Smalltalk if you use the object-oriented extensions
  14. 15. It allows experienced programmers to mix different programming styles in the same program </li></ul></ul><li>It is extremely flexible </li></ul>
  15. 16. Objective-C Support <ul><li>Compilers </li><ul><li>Apple GCC
  16. 17. FSF GCC </li></ul></ul><ul><li>Objective-C 2.0 </li><ul><li>Introduced by Apple in
  17. 18. Mac OS X 10.5
  18. 19. Garbage-collection
  19. 20. Threading/Exceptions
  20. 21. Fast Enumeration
  21. 22. Properties
  22. 23. Objective-C 1.0 code still compiles with a 2.0 compiler </li></ul></ul><ul><li>Runtime Libraries </li><ul><li>NeXT/Apple Runtime
  23. 24. GNU Runtime </li></ul><li>Core Objective-C Libraries </li><ul><li>Apple Cocoa
  24. 25. GNUstep </li></ul></ul>
  25. 26. Writing Portable Objective-C Code On Apple Mac OS X , avoid Objective-C 2.0 syntax such as properties and fast enumerations. On Apple Mac OS X , avoid garbage collection and use explicit the traditional OpenStep reference counting. This is likely to change – GNUstep is getting garbage collection again. On both Apple and GNUstep , If you need to access the runtime, use an intermediate layer such as the one provided by gnustep-base additions.
  26. 27. History of Objective-C Core Frameworks
  27. 28. OpenStep API Specification (1994)
  28. 29. OpenStep API Specification (1994) <ul>Foundation Kit Non-graphical classes <ul><li>Root classes : NSObject, NSProxy
  29. 30. Basic data classes : NSString, NSNumber, NSData, NSNull
  30. 31. Collection classes : NSArray, NSDictionary, NSSet
  31. 32. Execution control classes : NSRunLoop, NSTimer, NSThread, NSLock
  32. 33. I/O classes : NSTask, NSFileHandle
  33. 34. Notification classes: NSNotification, NSDistributedNotification
  34. 35. Serialization classes: NSArchiver, NSCoder
  35. 36. Resource management classes: NSBundle, NSUserDefaults
  36. 37. Distributed Objects Classes: NSConnection, NSPort
  37. 38. And many more... </li></ul></ul>Application Foundation Kit Application Kit Operating System OS Graphical System Objective-C Runtime
  38. 39. OpenStep API Specification (1994) <ul>Application Kit Graphical classes <ul><li>Window classes : NSWindow, NSPanel
  39. 40. Menu classes : NSMenu, NSMenuItem
  40. 41. Basic drawing classes : NSView, NSColor, NSFont, NSGraphicsContext
  41. 42. Basic interaction classes: NSEvent, NSResponder, NSControl, NSCell
  42. 43. Control classes : NSButton, NSTextField, NSBrowser, NSPopUpButton, NSMatrix
  43. 44. Table classes: NSTableView
  44. 45. Text classes : NSTextView, NSTextStorage, NSLayoutManager, NSInputManager
  45. 46. Scrolling classes: NSClipView, NSSplitView, NSScrollView,
  46. 47. Standard panel classes: NSFontPanel, NSSavePanel
  47. 48. And many more... </li></ul></ul>Application Foundation Kit Application Kit Operating System OS Graphical System Objective-C Runtime
  48. 49. Apple Cocoa Application Cocoa Foundation Kit Cocoa Application Kit Operating System (Apple Darwin/BSD) OS Graphical System Apple Objective-C Runtime
  49. 50. GNUstep Application GNUstep Base GNUstep GUI Operating System (Any!) Graphical System (Any!) GNU Objective-C Runtime GNUstep Back
  50. 51. Portability <ul>GNUstep: <ul><li>GNU/Linux
  51. 52. OpenBSD, FreeBSD, *BSD
  52. 53. OpenSolaris, HP UX, other Unix systems
  53. 54. Microsoft Windows </li></ul></ul><ul>Apple Cocoa: <ul><li>Apple Mac OS X </li></ul></ul>
  54. 55. Writing Portable Objective-C Code On Apple Mac OS X , avoid Apple-only frameworks such as CoreFoundation, CoreSound, CoreAnimation, KeyChain, Carbon, Quartz, Quicktime, WebKit. On GNUstep , avoid GNUstep extensions that are not available as a separate library or framework that works on Apple as well.
  55. 56. Foundation Kit Example #import <Foundation/Foundation.h> int main (void) { NSLog (@“Hello world!”); return 0; } <ul>A (Trivial) Portable Objective-C Program File hello.m: </ul>
  56. 57. Building the Foundation Kit Example On Apple Mac OS X , there is XCode <ul><li>Only for Apple Mac OS X
  57. 58. Complete, total IDE
  58. 59. It uses its own files
  59. 60. Hard to work with developers who use other platforms where Xcode is not available </li></ul>
  60. 61. Building the Foundation Kit Example On GNUstep , there is Project Center <ul><li>Works everywhere
  61. 62. Similar to XCode
  62. 63. Lagging in features (this might change)
  63. 64. Uses its own files, then generates
  64. 65. gnustep-make GNUmakefiles
  65. 66. to build </li></ul>
  66. 67. Building the Foundation Kit Example On GNUstep , there is also gnustep-make <ul><li>Works everywhere,
  67. 68. even without a GUI
  68. 69. Makefile library designed to make building complex projects easy
  69. 70. Official building system for GNUstep
  70. 71. Very complete
  71. 72. Editable, portable text files
  72. 73. Requires editing text files - not a point-and-click GUI IDE </li></ul>include $(GNUSTEP_MAKEFILES)/common.make TOOL_NAME = hello hello_OBJC_FILES = hello.m include $(GNUSTEP_MAKEFILES)/tool.make
  73. 74. Building the Foundation Kit Example Not Portable Portable GUI IDE Text files include $(GNUSTEP_MAKEFILES)/common.make TOOL_NAME = hello hello_OBJC_FILES = hello.m include $(GNUSTEP_MAKEFILES)/tool.make XCode Project Center gnustep-make Pbxbuild can generate GNUmakefiles from Xcode projects
  74. 75. More Foundation Kit Portability Issues <ul>Loading and locating resources and files <ul><ul><li>Windows paths
  75. 76. Unix filesystem layout </li></ul><li>=> Always use the OpenStep API (NSBundle, NSPathUtilities)
  76. 77. Tools with Resources (GNUstep) are not available on Apple </li></ul>Frameworks vs Shared libraries <ul><ul><li>Frameworks are shared libraries with resources
  77. 78. Apple has native linker implementation, GNUstep emulates them
  78. 79. Emulation can be inefficient/inappropriate on some platforms </li></ul></ul></ul>
  79. 80. Even More Foundation Kit Portability Issues #ifdef GNUSTEP /* GNUstep-specific code */ #else /* Apple-specific code */ #endif #ifndef GNUSTEP # include “GNUstep.h” #endif Platform-dependent Code <ul><ul><ul><li>User GNUSTEP preprocessor define, which is defined on GNUstep but not on Apple </li></ul></ul></ul>GNUstep macros <ul><ul><ul><li>ASSIGN, RELEASE, etc
  80. 81. Use GNUstep.h (eg, from Renaissance) </li></ul></ul></ul>
  81. 82. Application Kit Programs <ul>If you create your GUI using the OpenStep API, it's pretty much the same ... </ul>... buttons[0] = [[NSButton alloc] initWithFrame: NSMakeRect (77, 3, 34,24)]; [buttons[0] setButtonType: NSToggleButton]; [buttons[0] setTitle: @&quot;0&quot;]; [buttons[0] setTag: 0]; [buttons[0] setState: NO]; [buttons[0] setAction: @selector(digit:)]; [buttons[0] setKeyEquivalent: @&quot;0&quot;]; ... PS: most developers don't use the OpenStep API directly but use Xcode or Gorm or Renaissance. We'll look at these tools later.
  82. 83. Menu Portability (hard) On Apple you must use the Apple-only method NSApplication -setAppleMenu: which is not part of OpenStep and not even declared in a public header (!!).
  83. 84. Menu Portability (hard) <ul><li>On Apple you need to use a goofy private Apple-only setup.
  84. 85. On GNUstep and Apple the standard organization of menus (location of menu items, etc) are very different. </li></ul>
  85. 86. Example: Gomoku.app <ul>http://www.gnustep.it/nicola/Applications/Gomoku <li>A small game , originally for GNUstep only
  86. 87. It uses only the OpenStep API
  87. 88. It creates all the GUI in code
  88. 89. It has separate code to create the menu
  89. 90. on Apple Cocoa and GNUstep
  90. 91. It has a GNUmakefile and is built
  91. 92. using gnustep-make </li></ul>You can use it as an example of how to build a portable GUI in code .
  92. 93. Example: Gomoku.app <ul>http://www.gnustep.it/nicola/Applications/Gomoku </ul>
  93. 94. Example: Gomoku.app <ul>http://www.gnustep.it/nicola/Applications/Gomoku </ul>
  94. 95. Example: Gomoku.app <ul>http://www.gnustep.it/nicola/Applications/Gomoku </ul>
  95. 96. Creating GUIs without code On Apple Mac OS X , there is Interface Builder <ul><li>Only for Apple Mac OS X
  96. 97. Brilliant tool, extremely usable
  97. 98. and fast
  98. 99. It uses its own files (“Nib”s)
  99. 100. NIB files serialize GUI objects,
  100. 101. including platform-specific attributes such as fonts, sizes and colors
  101. 102. Static layout
  102. 103. Need to manually create a different NIB file for each language </li></ul>
  103. 104. Creating GUIs without code On GNUstep , there is Gorm <ul><li>Works on GNUstep
  104. 105. Very similar to Interface Builder
  105. 106. Uses its own files (“Gorm” files)
  106. 107. Same pros/cons as Interface
  107. 108. Builder
  108. 109. Can import NIBs from Interface Builder (they might need manual adjustment after importing) </li></ul>
  109. 110. Creating GUIs without code On GNUstep , there is also Renaissance https://www.gnustep.it/Renaissance <ul><li>Works everywhere
  110. 111. GNU LGPL framework
  111. 112. Open XML file format
  112. 113. Not that complete
  113. 114. Lacking a GUI builder
  114. 115. Editable, portable text files
  115. 116. Autolayout using boxes and grids
  116. 117. Can load up translations at runtime: a single file can support all
  117. 118. languages </li></ul><gsmarkup> <objects> <window title=&quot;This is a test window&quot;> <button title=&quot;Print Hello!&quot; action=&quot;printHello:&quot; /> </window> </objects> </gsmarkup>
  118. 119. Creating GUIs without code Not Portable Portable GUI IDE Text files <gsmarkup> <objects> <window title=&quot;This is a test window&quot;> <button title=&quot;Print Hello!&quot; action=&quot;printHello:&quot; /> </window> </objects> </gsmarkup> Interface Builder Gorm Renaissance Renaissance GUI Builder (TODO)
  119. 120. The future of free, cross-platform Objective-C <ul>Free, cross-platform Objective-C needs your help! <ul><ul><li>Try out the GNUstep frameworks and tools
  120. 121. Give constructive feedback, suggest improvements, provide patches
  121. 122. Create examples, tutorials
  122. 123. Write applications
  123. 124. Port existing applications back and forth between GNUstep and Apple Cocoa
  124. 125. Help improving GNUstep ports to Windows and
  125. 126. other platforms </li></ul></ul></ul>

×