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
Let Xcode help. You know the framework is "System Configuration" by looking at the documentation. So in your source file start typing:
and Xcode will start offering suggestions. And the first one you see after entering the above just happens to be for what you need:
The basic pattern will work for most frameworks.
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.
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):
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.