1. Ivan Vučica
  2. php-objc

Commits

w...@c90b9560-bf6c-de11-be94-00142212c4b1  committed 318449b

kick off objc bits

  • Participants
  • Branches default
  • Tags start

Comments (0)

Files changed (1)

File README

View file
  • Ignore whitespace
+This is an Objective-C bridge for PHP, allowing PHP to create and call into the
+Objective-C runtime, and vice versa.
+
+It plumbs the Objective-C auto-load mechanism into PHP, so that you may author
+NIB files that reference classes implemented in PHP and have those instantiated
+when parts of your user interface are loaded.
+
+Objective-C supports what some people call "mutil-method dispatch" and others
+call "method overloading", where two methods can have the same name but a
+different set of parameters.  The way that this works is by encoding the
+parameter names into the method names, so it's really just an illusion.
+
+Here's a quick start guide to mapping Objective-C method names into PHP, using
+the NSApplication class as an example.
+
++ (NSApplication *)sharedApplication
+
+  this is a static method of the NSApplication class, the PHP way to call it is this:
+  
+  $App = NSApplication::sharedApplication();
+
+- (void)setDelegate:(id)anObject
+
+  this is a regular "instance" method of the NSApplication object, call it like this:
+  
+  $App->setDelegate_($anObject)
+  
+  note that the : is translated to an underscore.
+
+- (id)targetForAction:(SEL)anAction to:(id)aTarget from:(id)sender
+
+  $App->targetForAction_to_from_($anAction, $aTarget, $sender);
+  
+  note that the names before the colons are encoded into the method name
+
+
+Method signature hackery
+
+The bridge isn't quite smart enough to automatically figure out type mapping
+for everything, particularly if you are declaring a delegate object that will
+act as a sink for events, so you will need to provide hints in some cases.
+
+You can provide the hints using doc-comments like this:
+
+class MyDelegate extends NSObject {
+	/** @objc:signature c@: */
+	function run_() {
+		echo "*** run!\n";
+	}
+}
+
+the "c@:" part defines the return type and parameters for the run_ method; it
+is a standard objective-C stype signature.
+
+A TODO item is to also examine @param and @return doc comments, but this is
+hard because there isn't always a good way to map them.
+
+
+Some resources:
+
+http://developer.apple.com/reference/Cocoa/idxObjectiveCLanguage-title.html#doclist
+
+http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/index.html
+
+http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html#//apple_ref/doc/uid/TP40001418
+
+