Legolas Wang
Legolas Wang

Reputation: 2559

How can I edit a Markdown file in Xcode?

I can't figure out how can I edit a Markdown file in Xcode. The file appears to be rendered in a read only mode. Is there any setting that allows me to edit Markdown files in Xcode?

I'm trying to add note to apple's sample project's README.md https://developer.apple.com/documentation/pencilkit/drawing_with_pencilkit

Screenshot of a Markdown file opened in Xcode

Upvotes: 8

Views: 6402

Answers (3)

par
par

Reputation: 17724

As of Xcode 13.2.1 this is still broken. Here's an ugly workaround:

  1. Create a file in your Project.xcodeproj/ directory named .xcodesamplecode.plist and copy into it the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array/>
</plist>
  1. Step 1 will cause Xcode to render README.md as markdown in read-only mode.

  2. To edit the markdown, close all windows and/or tabs in which README.md is visible.

  3. Rename README.md to anything else with a .md suffix, for example editable.md.

  4. Now open editable.md and it will be editable.

  5. When finished editing close all editable.md windows and rename it back to README.md.

  6. File a bug report with Apple.

Upvotes: 2

CodeFarmer
CodeFarmer

Reputation: 2708

For xcode 12:

Right inspector panel, change Type to be: swift source

Close editor

Right click file, 'open as source code' again

Upvotes: 4

glyvox
glyvox

Reputation: 58099

If your .md file is uneditable, you're likely not in Source Code mode. Right click on the file in the Project navigator (the left panel on your screenshot, if it's not visible, press Cmd+1) and select Open As/Source Code.

Screenshot of the context menu

If you want to edit .md files in an Xcode project downloaded from the Apple Developer site, delete these two files in the project folder before opening the project:

Configuration/SampleCode.xcconfig
[project name].xcodeproj/.xcodesamplecode.plist

Here's how too access the second file:

  • Right-click on the .xcodeproj file in Finder and select Show Package Contents.
  • If hidden files are not visible in Finder, press ⌘⇧. (Cmd+Shift+period).

Upvotes: 13

Related Questions