This guide will help you to get started with TurboCocoa for iOS and OS X.

Environment setup

To develop apps for OS X or iOS you need to use a Mac machine.

TurboCocoa requires Embarcadero Delphi XE8 or Seattle on Windows side and OS X 10.9 with Xcode 7 or higher on the Mac side.

There are few useful link to setup your environment from Embarcadero:

Set Up Your Development Environment on the Mac Set Up Your Development Environment on Windows PC

Once you've got all required steps done, you are ready to use TurboCocoa.

Programming in Delphi

When you develop native application for iOS or OS X the structure of application is different from a typical Delphi application.

It is similar to a native Cocoa application coded with Objective-C or Swift.

Typical structure of iOS application:

Properties\Info.plist - Application plist declaration

Resourses\Base.lproj\LaunchScreen.storyboard - Application launch screen UI design

Resourses\Base.lproj\Main.stroyboard - Main application UI

AppDelegate1.pas - Application entry point, where AppDelegate class is declared and implemented.

ViewController1.pas - Implemenetation of Root view class

Depends on application kind, project can also contains additional Delphi unit with additonal class implementations.

Outlet declaration

To link UI and code, Xcode uses special kind of objects called outlets. You can declare outlet directly in Delphi code using [IBOutlet] attribute.

Example of outlet declaration:

...

[IBOutlet]

property MyOutlet: UILabel read FMyOutlet write FMyOutlet;

...

...

[IBOutlet]

property MyOutlet: UILabel read FMyOutlet write SetMyOutlet;

...

To synchronize Delphi code and Xcode, just save the project and select Launch Xcode in Project context menu.

Action declaration

To handle UI action, Xcode uses special kind of method called actions. You can declare an action directly in Delphi code using [IBAction] attribute.

...

[IBAction]

procedure ButtonClick(id: Pointer);

...

Designing in Xcode

TurboCocoa hasn't got any internal UI designer, it uses native way of UI design process. For OS X and iOS platform it is a Xcode Designer.

Native Cocoa application's uses XIB or Stroryboard to design UI. TurboCocoa is integrated directly into Xcode and provide a bridge between Delphi code and XIB or storyboard files.

When you application is opened in Delphi, TurboCocoa agents allow synchronization of the code and UI and vise versa.

To launch Xcode designer, right click on Project and select "To Xcode" menu item. If all connections are setup successfully, Xcode is launched on Mac side.

To link UI and code, TurboCocoa creates temporary mirrored Objective-C classes based on Delphi code. All mirror-classes located in Classes.h and Classes.m.

If Delphi code has TurboCocoa outlets or/and actions, it is automatically added to stub classes. In addition TurboCocoa agents parse all project's *.pas files and create mirror classes for every Objective-C classes.

Delphi code:

Generated Xcode code:

Designing UI in Xcode

When designing iOS project, open Storyboard file in Xcode. For OS X you should select XIB file.

Typical screen for iOS storyboard designing:

Link Delphi outlet

All declared Delphi outlet available in Xcode after synchronization.

You can link UI controls and objects to this outlet in Xcode Inspector:

Just click on plus icon and move selection to object which you want to link in the structure view.

Link Delphi action

All declared Delphi actions are available in Xcode after synchronization.

You can link UI control's action using Xcode Inspector:

Click on "plus" icon and move selection to action owner item which you want to link to in the structure view.

Another way to link action is right click on control and move selection to action owner:

FAQ Docs Videos Samples About Us