skip to Main Content

I’m new to macOS development, so pardon my simplistic question. Say, if I have a function. Let’s take SCError for example. From the documentation I can see that I need to add:

System Configuration framework

But how do I know which header file to add, so that I don’t get Use of undeclared identifier 'SCError‘?

PS. I’ll give an example of a documentation that doesn’t make me ask these questions. Say, GetLastError. It states at the bottom of the page:

Header:     errhandlingapi.h (include Windows.h)

So it’s clear for me what to do:

#include Windows.h

So what am I missing with the Apple documentation?

2

Answers


  1. Let Xcode help. You know the framework is "System Configuration" by looking at the documentation. So in your source file start typing:

    #import <Sy
    

    and Xcode will start offering suggestions. And the first one you see after entering the above just happens to be for what you need:

    #import <SystemConfiguration/SystemConfiguration.h>
    

    The basic pattern will work for most frameworks.

    #import <FrameworkName/FrameworkName.h>
    

    Again, let Xcode show you likely candidates as you start typing the first few letters. Then it’s easy to select the match so the rest is entered for you.

    Login or Signup to reply.
  2. Several solutions:

    Consult the documentation. You look at the SCError documentation at it shows you it’s part of the System Configuration framework (currently, in at least two places: the breadcrumbs near the top and the navigation list on the left). Usually, that’s what you need to import (without spaces):

    // Modern style.
    @import SystemConfiguration;
    // Old style.
    #import <SystemConfiguration/SystemConfiguration.h>
    

    Another solution is to use Cmd+Shift+O in Xcode (File > Open quickly …). Enter SCError, and go to the definition of this function. Again, the breadcrumbs tell you which framework this function lives in: Frameworks > SystemConfiguration. This again leads to the same imports as mentioned above.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search