Write the Sketch

The newly created project contains various files:

  • The file main.cpp calls the appropriate core libraries, initialises the board, includes the sketch. The main() function calls the setup() and loop() functions from the sketch. Do not alter this file.

  • The embed1.pde or embed1.ino file is where you write the sketch, with the setup() and loop() functions and all the additional ones.

  • The files LocalLibrary.h and LocalLibrary.cpp are the header and the code for the LocalLibrary library. They are provided as example.

  • The file makefile is the entry for the compilation processes. Do not alter this file.

The files you can play with are the embed1.pde or embed1.ino files for the sketch, and the LocalLibrary.h header and LocalLibrary.cpp code for the LocalLibrary library.

A project can only have one .ino file, except for Energia MT on the LaunchPad MSP432 and CC3200.

The files of the newly created project include links to the online user manual.

// Core library for code-sense - IDE-based
// Help: http://bit.ly/2x8HivE
#if defined(WIRING) // Wiring specific
#include "Wiring.h"
...
  • Press Cmd and hover the cursor of the mouse over the link.

The cursor of the mouse changes for a hand .

  • While maintaining Cmd pressed, click on the link to open the related page, or Cmd+Left Button.

Other files also feature help links, including the main Makefile and the Doxygen file.

Use Code-Sense

Code-sense is a major feature of Xcode.

Apart from pretty colours on the code and enhanced visibility, code-sense brings many features that speed up coding.

However, code-sense faces some limitations. For example, macros calling other macros are poorly indexed, resulting in lines with standard black characters.

Use Auto-Completion

First, check auto-completion is turned on:

  • Call the menu Xcode > Preferences,

  • Select the tab Text Editing > Editing,

  • Check Suggest completions while typing.

To use auto-completion,

  • Type the first letters and Xcode completes.

  • Select one item of the list and press tab.

To use code-snippets and check-as-you-type code monitoring,

  • Type the first letters and Xcode completes.

  • Fill-in each parameter and press tab to go to the next one.

Get Quick Help

The Quick Help feature displays on the Utilities panel all the available documentation for the function under the cursor:

To use click-to-definition,

  • Place the cursor on a function.

  • Press Cmd+Left Button to access a function definition.

Notice the hand .

Xcode displays the function.

As a variant, to use the contextual help,

  • Place the cursor on a function.

  • Press Alt+Left Button to display the definition.

Notice the question mark .

Xcode opens a dialog box with all the information.

Sometimes, the index of keywords needs to be re-indexed.

For the Cosa object-oriented framework, the documentation is automatically provided in embedXcode when typing.

Help provides detailed documentation on a specific function.

Help lists the functions of an object.

Use the Touch Bar

Xcode provides useful short-cuts if your Mac features a Touch Bar. However, with Xcode on any Mac, call the menu Window > Show Touch Bar or press Cmd+Shift+5 to display the Touch Bar on the screen.

Alternatively, install and use a utility like Touché .

Use Bookmarks

We can use the breakpoints as bookmarks.

To display the bookmarks,

  • Click on the Breakpoint Navigator button:

To add a bookmark,

  • Select the line:

  • Click on the line number, here 113 of function loop(). The bookmark is added.

Multiple bookmarks can be added. They are grouped by file within the project.

To reach a position,

  • Just click on the bookmark you want to go, here line 104 of setup().

Please note bookmarks are actually breakpoints. They may conflict with the debug mode.

None of the Processing-based Wiring-derived Arduino-like IDEs has implemented debugging yet, except Energia for the LaunchPad boards.

To disable or remove the breakpoints,

  • Please refer to Define the Breakpoints section.

Commit and Compare Code Versions

Xcode manages versions if source control has been checked when creating the new project.

Commit a New Version

To commit a new version, call the menu Source Control > Commit or press Cmd+Alt+C.

  • Select the files to commit.

  • Enter a comment.

  • Click on Commit the Files.

Compare Versions

To compare versions, use the dedicated version editor.

  • To display the version editor, call the menu View > Version Editor > Show Version Editor or press Cmd+Alt+Shift+Enter or click on the button shown below.

The current and previous versions are displayed alongside.

In this example, line 103 has changed:

The button allows to discard changes.

The versions can be selected among the previously saved versions.

For more informations on this feature and on others,

  • Please refer to the Xcode help.

Re-Index the Keywords for Code-Sense

Code-sense is a major feature of Xcode. Sometimes, keywords need to be re-indexed.

Apart from pretty colours on the code and enhanced visibility, code-sense brings:

  • Auto-completion,

  • Code-snippets and check-as-you-type code monitoring,

  • Click-to-definition

If code-sense doesn't work, we need to force a re-indexing of the keywords.

To do so,

  • First close the project.

  • Call the menu Window > Projects.

The Projects window opens and shows the list of the projects.

  • Select the project.

The blue dot close to embed2 means this project is open.

  • If a blue dot appears close to embed1, close the project first.

The index is saved within the Derived Data folder.

  • Click on the Delete... button to delete the index.

  • Confirm the deletion with Delete.

  • Load the project again.

There's no code-sense yet: everything is in black-and-white, except standard C++ keywords in red, pre-processing statements in brown, comments in green and numbers in blue.

The index is being built again.

Once the index is built, code-sense shows pretty colours.