Saturday, October 14, 2023
HomeiOS DevelopmentSwift DocC: Tips on how to Host Doc Archive on Internet Server...

Swift DocC: Tips on how to Host Doc Archive on Internet Server and GitHub Pages


Swift DocC is a documentation compiler launched by Apple in Xcode 13, designed to assist builders create elegant and interactive documentation for his or her iOS and macOS tasks. The compiler converts your Markdown-based remark into wealthy documentation. With Swift Docc, you may incorporate code snippets, diagrams, and even interactive tutorials immediately into your documentation, enabling readers to realize a deeper understanding of your code and the way it works.

The generated documentation is displayed immediately within the Xcode documentation window, giving builders a seamless and built-in expertise. Along with with the ability to show your documentation in Xcode, you too can host it on an internet site. It is a nice technique to share your documentation with a wider viewers and make it extra accessible.

On this tutorial, I’ll provide you with a fast walkthrough of Swift DocC and present you the way to publish the code documentation onto your personal net web page or share it on GitHub Web page.

Documenting Your Swift Code with DocC

To create documentation utilizing DocC, you’ll want to make use of a customized variant of Markdown known as documentation markup. The syntax is much like Markdown however it provides performance for code documentation-specific options similar to cross-symbol hyperlink and time period lists. Assuming you’ve gotten some expertise with Markdown, you need to know the way to use documentation markup.

To doc your supply code in Xcode, you may maintain the command key and click on the tactic title.

swiftui-docc-add-documentation

By selecting the Add Documentation choice, Xcode will generate a template that features placeholders for all the required components. You possibly can then write your personal description to supply details about the operate and parameters.

On prime of the documentation of your Swift information, DocC lets you create a touchdown web page (or a top-level web page) that gives an summary of your challenge and serves as an entry level of your code documentation.

Though DocC can generate a primary touchdown web page for you, it’s all the time really helpful to create your personal entry web page to provide your documentation a novel and personalized effect. Xcode makes this simple by robotically creating an empty touchdown web page while you add a documentation catalog to your challenge.

swift-xcode-documentation-catalog

Under is the Markdown file for the touchdown web page of our MotionBar challenge. The primary line of the documentation file is the challenge title with an H1 heading. Within the content material half, you present an summary about your challenge and any extra data that helps different perceive your code.

Xcode-docc-landing-page

To assist your reader navigate by the supply code, you may group your construction and courses into completely different matters. You begin with the Matters key phrase, adopted by part names for every group of sophistication/construction.

swift-docc-topics

That is only a fast walkthrough of the way you format your code documentation utilizing documentation markup. If you wish to dive deeper into the markup language, you may consult with the official documentation of DocC.

Producing DocC Documentation from Xcode

To observe the remainder of the tutorial, I recommend you to obtain the demo challenge SlothCreator developed by Apple. The pattern challenge exhibits you the way to make use of DocC to create code documentation and tutorials.

swift-docs-build-documentation

Constructing your documentation is a breeze with Xcode’s built-in capabilities. To take action, merely navigate to the Xcode menu and choose Product > Construct Documentation. Xcode will then convert your Markdown-based feedback right into a fantastically designed documentation that appears much like the official Apple API documentation.

swift-docs-slothcreator-doc

In the event you’re trying to export your documentation as a doc archive, merely click on the ... button situated subsequent to SlothCreator and choose Export. This can can help you select your required location and save the exported documentation with a .docarchive file extension.

swift-docc-export-documentation

Constructing a DocC Archive Utilizing Command Line

In the event you want constructing documentation utilizing Terminal, the doc compiler additionally gives the next command to create a doc archive:

Let’s use the SlothCreator challenge for example. Open Terminal and alter to the SlothCreator listing (for me, I retailer the challenge beneath my Downloads folder):

Sort the next command to construct the documentation:

The Doc Builder software ought to then generate the doc and put it aside beneath the construct folder. You’ll discover a number of subfolders beneath the construct folder. The doc archive is situated beneath construct/Construct/Merchandise/Debug-iphonesimulator.

swift-docc-archive

In the event you can’t find the doc archive file, you should utilize the discover command to seek for it:

Changing DocC Archive for Static Internet hosting

When you efficiently find the doc archive, you may zip it and share it immediately together with your workforce members by way of electronic mail or AirDrop. They will open the DocC archive utilizing Xcode.

When Xcode exports a documentation archive, it features a single-page net software throughout the bundle. This net app is designed to render the documentation content material as HTML. Nevertheless, to host the archive on an online server, you’ll want to change your net server configuration and add some routing guidelines. Here’s a pattern configuration of Apache (i.e. .htaccess) offered by Apple:

If you don’t want to edit the server configuration, DocC additionally lets you convert the doc archive for static internet hosting through the use of the next command:

By utilizing the transform-for-static-hosting choice, DocC can generate static hyperlinks with out requiring you to arrange customized routing guidelines.

To proceed with our SlothCreator demo, you may convert the doc archive by working the next command:

If all the things runs easily, DocC generates the HTML information beneath the htmldoc folder. You possibly can copy the information to your net server and entry the documentation like this:

For the tutorials, it’s out there right here:

By default, DocC assumes you host the information beneath the foundation / path. In the event you want to host the documentation beneath a subfolder, you may add the choice hosting-base-path when executing the command above like this:

We set the bottom path to /demo. On this case, you’ll entry the documentation utilizing the next URL:

Internet hosting the DocC Documentation on GitHub Pages

To host the documentation on GitHub web page, you first create a brand new repository named username.github.io, the place username is your username (or group title) on GitHub.

docc-github-create-repository

Subsequent, clone the brand new repository and retailer in your most well-liked challenge folder utilizing the command under:

You’ll want to exchange the instance username and repository title with your personal. As soon as your repository is about up, you may then copy the documentation information that you simply beforehand ready into the challenge folder.

For me, since I take advantage of the foundation path as the bottom path, I simply copy your whole DocC information into the folder named appcoda.github.io.

Now it’s prepared so as to add and add the information to your distant repository. Key within the following instructions beneath your challenge folder:

As soon as all information are uploaded onto GitHub, you need to have the ability to entry your documentation at https://.github.io/documentation/slothcreator.

swiftui-docc-github-hosting

Abstract

Internet hosting your Swift DocC documentation on an online server is a superb technique to share your documentation with a wider viewers and make it extra accessible. By following the steps on this tutorial, you may simply create elegant documentation to your iOS and macOS tasks. And yo’ve discovered the way to publish it by yourself web site or on GitHub Pages. With DocC, you may incorporate diagrams and even interactive tutorials immediately into your documentation, enabling readers to realize a deeper understanding of your code and the way it works. So give DocC a attempt to make your documentation extra attention-grabbing!





Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments