Creating a Preference Pane Bundle
This section takes you through the steps to create and install a preference pane bundle for use by System Preferences. You need to perform these actions for every preference pane you create. It is assumed that you are already familiar with Xcode and Interface Builder. For help using these development tools, see the Currency Converter tutorial for Cocoa.
Create the Project
This section describes how to create the preference pane project and add the Preference Panes framework.
Choose New Project from the File menu.
Select the Cocoa Bundle project type and create the project.
Choose Add Frameworks from the Project menu. If the selection is not already there, go to the
Create the Nib File
This section describes how to create a simple preference pane nib file and add it to the preference pane project.
While Xcode is still running with your project open, start Interface Builder.
Create an empty Cocoa nib.
Create a window and resize it to a suitable size. For System Preferences, the window should not be more than 595 pixels wide. As the window itself is not used by the preference pane, only its contents, you do not need to specify a window title nor localize the title.
Build the user interface in the window.
Return to Xcode and locate the
NSPreferencePane.hheader file in
PreferencePanes.framework. Drag the header file to the nib’s main window in Interface Builder.
In the Classes pane, select the NSPreferencePane class and create a subclass of it. Rename it to whatever you want. This is a global property within the preference application, so include a unique prefix in the name as described in “Preventing Name Conflicts.”
With the subclass selected, go to the Attributes pane of the Info window. Create any outlets or actions you need for the user interface.
In the Instances pane, select the File’s Owner object. In the Custom Class pane of the Info window, select your preference pane class.
Draw a connection (Control-drag) between the File’s Owner object and the window object. Connect the window to the
Connect the remaining outlets and actions needed for the user interface.
Save the nib file into the
English.lprojdirectory of your project. When asked whether to add it to the project, click the Add button.
Create the Preference Pane Files
This section describes how to create the initial source files and to insert the preference pane’s icon into the project.
In Interface Builder, with the nib file open, click the Classes tab and select your preference pane subclass.
Choose Create Files from the Classes menu. Save the files in your project folder and make sure the “Insert into targets” checkbox is checked.
In Xcode, edit the header file of your preference pane subclass. After the line importing
Cocoa.h, add the line
Add your preference pane icon to the project’s Resources folder.
Update the Build Settings
This section describes how to modify the default project settings to produce a custom preference pane bundle. This mostly involves assigning values to the necessary keys in the bundle’s information property list.
Choose Edit Active Target from the Project menu and go to the Bundle Settings pane.
Change the “Identifier” field to an appropriate unique value for the
CFBundleIdentifierkey. The value should be prefixed by the reverse domain name of your organization (see “Preventing Name Conflicts”).
Change the “Principal class” field in the Cocoa-specific section to the name of your preference pane subclass. This is the
Change the “Main nib file” field to the name of your nib file. Do not include the
.nibextension. This is the
Enter Expert mode by clicking the Expert button at the top of the Bundle Settings window. Create a new key by clicking the New Sibling button. Rename the new key
NSPrefPaneIconFileand set its value to the name of your icon file.
Go to the Build Settings pane, scroll to the bottom of the window, and change the
WRAPPER_EXTENSIONentry value to
InfoPlist.stringsfile in the project’s Resources folder. Update the
CFBundleNamevalue if it should be different from the project name. Alternatively, you can add an entry for
NSPrefPaneIconLabel, if you need to split the name between two lines.
Build and Install the Preference Pane
This section describes how to make the preference pane available to System Preferences.
Build the project.
In Finder, locate the
builddirectory for the project. The default location is inside the project folder. The preference pane is in this folder.
Move the preference pane into one of the
PreferencePanesfamily of folders listed in “Where Preference Panes Live.” For testing, use the
~/Library. You may need to create the
When you run System Preferences you should now see your preference pane at the bottom of the window in the “Other” category.
© 2003, 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-12-13)