Creating a New Project
Adding UI (Outlets and Actions)
These are preliminary notes on some new tools for creating Objective Pascal
projects for Xcode.
- Free Pascal compiler
Install version 3.0.0 or later.
- ProjectXC source code
- Compile makeproj.pas
Creating a New Project
Run makeproj, specifying a template to use and the name of
the project to create. For example, to create an OS X project:
./makeproj osx-simple ~/MyProjects/test1
Change ~/MyProjects to point to an existing folder where you want the
test1 project folder to be created.
Now open test1.xcodeproj in Xcode and choose Product | Run to compile and
Adding the UI (Outlets and Actions)
An OS X project created based on the osx-simple template is:
As an example, here's how to add a button to a new project based on the
- Simple, not document-based
- Uses a storyboard for UI design, not a xib file
- Does not use Core Data
- Includes "dummy" Objective C files that are only used for designing
the user interface.
- In Xcode, expand your new project's folders in the Navigator panel
on the left.
- Select Main.storyboard to open the UI in its designer.
- Select the View Controller's View.
- Drag and drop a button on the View.
- To access the button's properties in code, you'll need to add an outlet
for it, as follows:
- Click the button in the upper right to show the
Assistant editor so you can edit two files at once.
- In the right editor, select ViewController.h from the menu at the top.
- Make sure the View's button is selected and not its inner NSButtonCell.
If in doubt, click the Quick help button (question mark) at the top
of the Utilities panel on the right. Make sure it shows NSButton.
- Click the Connections button at the top of the Utilities panel.
- Click the New Referencing Outlet's button and drag and drop it to where
indicated in ViewController.h. When prompted, enter button.
- To respond to the button's click event in code, you'll need to add an
action for it, as follows:
- Click the Sent Actions action's button and
drag and drop it to where indicated in ViewController.h.
When prompted, enter buttonClick.
- Now add the equivalent Pascal code to ViewControllerU.pas. Tip:
Copy the commented Pascal code in ViewController.h and paste it
where indicated in ViewControllerU.pas, removing the "//". Your code
should look something like the screenshot below.
- Choose Product | Run, then click the button to change its title to Clicked!.
Copyright 2015-2016 by Phil Hess.
macpgmr (at) icloud (dot) com
First posted Oct. 25, 2015; last edited Nov. 20, 2016.