I'd like to get Xcode 4 to recognize a custom file extension (e.g. *.lx) as Objective-C for syntax highlighting and indentation purposes. How do I get the tool to automatically do this?
-
I don't know how to automatically do this yet, but you can tell Xcode to recognize a file this way in the File Inspector panel. – james_womack Feb 13 '12 at 18:36
3 Answers
Xcode determines how to represent a file in its user interface based on the file's Uniform Type Identifier. As far as I know it's not possible to add additional file extension tags to an existing UTI, but you can declare a new UTI that conforms to the type you want to map to. The system will then associate the specified file extension(s) with your new UTI and through conformance Xcode and every other UTI-aware application will recognize the files as source code of the mapped type.
You may want to give some thought to where to declare to the new UTI. For example, if files of this type are being created by a tool the bundle for that tool would be the most appropriate location. In the absence of a better alternative you can create a stub application bundle and declare the new UTI there:
- Create a new Cocoa Application project in Xcode.
- In project settings, select the application target, then the Info tab.
- Create a new Exported UTI.
- Set the Identifier field to a unique name using reverse DNS notation for a domain that you control. For example,
com.yourdomain.objective-c-source
. - Set the Conforms To field to the UTI that you want to map to, such as
public.objective-c-source
. You can find this by browsing the list of system-declared UTIs or those exported in Xcode's Info.plist. - Set the Extensions field to the comma-separated list of extensions that you want to associate with the new UTI.
- Commit the change to the last field by pressing return or moving the focus to a different field.
- Build and run the application to register it with Launch Services.
- Restart Xcode.
Xcode should now use appropriate syntax highlighting for files with the specified extension(s).
If this doesn't work, check the Info.plist of the built application to ensure that all of the expected information is there without any trailing whitespace. You can also check that the UTI has been registered using lsregister
:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump
Search the output for your UTI's identifier and verify that it is present and active.

- 13,093
- 3
- 33
- 27
-
This worked! For C++ .ipp files, i used `public.c-plus-plus-source` as the identifier name. – Peter Ehrlich Jul 22 '14 at 03:02
-
-
1+1000 Works for me too for .leaf Vapor file extension. (conforms to -> public.html) – Anand Suthar Feb 04 '17 at 07:15
-
This looks complicated, but it's the ONLY method that works. Here's a more pictorial description of the same method: http://stackoverflow.com/questions/41961953/adding-syntax-coloring-to-xcode-for-unknown-file-extension-such-as-tcl – Steve Mar 03 '17 at 23:16
Xcode has a "Type" field in the "Attributes Inspector" (leftmost tab in "Utilities" right sidebar) for files in your project:
As you can see above, I set our project's Fastfile
to be recognized as a Ruby Script—which it is, despite lacking the expected .rb
extension. Yielding the expected syntax highlighting (with my custom color scheme):
Note: this only works if the file is added to your project within a group (not inside a folder reference):
This might not be ideal, but Xcode can't persist attributes of files which aren't explicitly tracked in the project file. Folders, by design, don't have entries for their contents in the Xcode project, since it's meant to be dynamic.

- 3,643
- 3
- 22
- 22
-
-
Thanks Brian, this is exactly what I needed and should be the accepted answer. – Jason L Perry Dec 11 '16 at 15:43
In Xcode when your file is active in the editor, you go to the Editor Menu -> Syntax Coloring -> Objective-C
This will apply objective-c syntax coloring to a file. Worked for me with a plain text file regardless of its extension.
This seemed to work for automatic indentation also

- 142
- 5
-
10What I am looking for is a way to automatically syntax highlight. Not manually. – user1175914 Feb 23 '12 at 02:41
-
This does automatic syntax highlighting for me inside the file I changed it for. Or do you mean change the 'Default for file type' syntax highlighting so that any file of that type has such highlighting? If so, I did find this workaround...haven't tested though: http://lists.apple.com/archives/xcode-users/2007/Dec/msg00679.html – pontidm Feb 24 '12 at 10:15