<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Subhronil Saha</title>
    <description>The latest articles on DEV Community by Subhronil Saha (@subhronilsaha).</description>
    <link>https://dev.to/subhronilsaha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F504201%2F71fbe98f-42ed-41a7-bd5b-57ccf4896cee.png</url>
      <title>DEV Community: Subhronil Saha</title>
      <link>https://dev.to/subhronilsaha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/subhronilsaha"/>
    <language>en</language>
    <item>
      <title>A practical guide to creating ring charts in Swift using the CPRingChart library</title>
      <dc:creator>Subhronil Saha</dc:creator>
      <pubDate>Sat, 21 Aug 2021 15:29:47 +0000</pubDate>
      <link>https://dev.to/subhronilsaha/a-practical-guide-to-creating-ring-charts-using-the-cpringchart-library-27oa</link>
      <guid>https://dev.to/subhronilsaha/a-practical-guide-to-creating-ring-charts-using-the-cpringchart-library-27oa</guid>
      <description>&lt;p&gt;&lt;strong&gt;CPRingChart&lt;/strong&gt; is a customisable Swift library for creating ring hollow pie-charts quickly and with just a few lines of code. You can add it to your Swift project using Cocoapods. &lt;/p&gt;

&lt;p&gt;The most widely used library for making these kind of charts, in my opinion, is probably the amazing &lt;strong&gt;'Charts'&lt;/strong&gt; library by Daniel Gindi (&lt;a href="https://github.com/danielgindi/Charts"&gt;https://github.com/danielgindi/Charts&lt;/a&gt;). But unfortunately it does not provide the option to add rounded caps to your slices. Hence this library aims to solve that problem.&lt;/p&gt;

&lt;p&gt;In this example, we will go through an example project for demonstrating the functionality of this library.&lt;/p&gt;

&lt;p&gt;We will be using &lt;strong&gt;UIKit with Storyboards&lt;/strong&gt; but you can also use it without Storyboards if you want. &lt;/p&gt;

&lt;p&gt;So let's quickly setup the project. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open &lt;strong&gt;Xcode&lt;/strong&gt; and create a new App.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SDRuYtWX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ry8cqtfeivrtltmacai0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SDRuYtWX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ry8cqtfeivrtltmacai0.png" alt="Xcode-new-app" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I have named this project &lt;strong&gt;'CPRingChartExample'&lt;/strong&gt;, but you can name your project anything you want. Select &lt;strong&gt;'Storyboard'&lt;/strong&gt; as the app's Interface, and select &lt;strong&gt;'UIKit App Delegate'&lt;/strong&gt; as the app's lifecycle. We will not be needing Core Data, so I will leave the checkbox next to 'Use Core Data' unchecked.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Imf-Lwz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/260mwojy57f3v3gv9jvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Imf-Lwz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/260mwojy57f3v3gv9jvg.png" alt="Screenshot 2021-08-21 at 1.23.11 PM" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save the project where you can find it easily on your system. I have saved this project on my Desktop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cocoapods installation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now that your project is created, close the Xcode project and open the Terminal window.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We will be using Cocoapods to install this library, so make sure you have Cocoapods installed on your system. If you don;t have Cocoapods installed on your system, just use this command to install Cocoapods.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo gem install cocoapods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;     If you would prefer to use other installation methods, then you can refer the Cocoapods documentation: &lt;a href="https://guides.cocoapods.org/using/getting-started.html"&gt;https://guides.cocoapods.org/using/getting-started.html&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, in your Terminal window, navigate to your Xcode project folder's location using &lt;code&gt;cd&lt;/code&gt; command. I will be navigating using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd Desktop/CPRingChartExample
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, initialise Cocoapods in your project using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pod init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Open your Podfile &amp;amp; add the following line to it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="kt"&gt;CPRingChart&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Open Terminal, navigate to your project folder and run
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pod install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Importing the Library &amp;amp; Usage
&lt;/h2&gt;

&lt;p&gt;Now that we have CPRingChart added to our project, let's see how we can use it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the &lt;code&gt;.xcworkspace&lt;/code&gt; file created in your Xcode project folder. Open &lt;code&gt;ViewController.swift&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--enRVLV3P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a02ih9k4rsn0pr9cwbv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--enRVLV3P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a02ih9k4rsn0pr9cwbv3.png" alt="Screenshot 2021-08-21 at 7.56.54 PM" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replace all the existing code with the following in your &lt;code&gt;ViewController.swift&lt;/code&gt; file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="c1"&gt;//&lt;/span&gt;
&lt;span class="c1"&gt;//  ViewController.swift&lt;/span&gt;
&lt;span class="c1"&gt;//  CPRingChartExample&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;
&lt;span class="c1"&gt;//  Created by Subhronil Saha on 21/08/21.&lt;/span&gt;
&lt;span class="c1"&gt;//&lt;/span&gt;

&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;UIKit&lt;/span&gt;
&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;CPRingChart&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;ViewController&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;UIViewController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;@IBOutlet&lt;/span&gt; &lt;span class="k"&gt;weak&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;ringChart&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;CPRingChart&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;

    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;viewDidLoad&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;viewDidLoad&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="c1"&gt;// Ring chart setup here&lt;/span&gt;
        &lt;span class="n"&gt;ringChart&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sections&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
        &lt;span class="n"&gt;ringChart&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;ringChart&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fillColors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lightGray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;systemTeal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;systemOrange&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;systemPurple&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;systemPink&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;ringChart&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reloadChart&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;    I will be explaining this code below in &lt;strong&gt;&lt;em&gt;Code Explanation&lt;/em&gt;&lt;/strong&gt; section. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open &lt;code&gt;Main.storyboard&lt;/code&gt; and drop a UIView into the View Controller. Change its class to &lt;code&gt;CPRingChart&lt;/code&gt;. Also link it to the outlet &lt;code&gt;ringChart&lt;/code&gt; created earlier in &lt;code&gt;ViewController.swift&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BkagIBa7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jyj44z9zwfp8k1cn11mw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BkagIBa7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jyj44z9zwfp8k1cn11mw.png" alt="Screenshot 2021-08-21 at 8.01.48 PM" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run the Project. You should see this as the output.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4tHt5Ix2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dkhsosei4xqttkay8mb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4tHt5Ix2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dkhsosei4xqttkay8mb.png" alt="Screenshot 2021-08-21 at 8.15.27 PM" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Explanation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;CPRingChart has a few &lt;strong&gt;mandatory&lt;/strong&gt; properties that need to be set always. These are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sections&lt;/code&gt; - The number of sections/slices in the chart.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;values&lt;/code&gt; - A &lt;code&gt;Double&lt;/code&gt; array containing the values for each section. 

&lt;ul&gt;
&lt;li&gt;The length of &lt;code&gt;values&lt;/code&gt; should be always equal to &lt;code&gt;sections&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fillColors&lt;/code&gt; - An &lt;code&gt;UIColor&lt;/code&gt; array that specifies the color for each section. 

&lt;ul&gt;
&lt;li&gt;The length of &lt;code&gt;fillColors&lt;/code&gt; should always be equal to &lt;code&gt;sections&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Other &lt;strong&gt;optional&lt;/strong&gt; properties include the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;spacing&lt;/code&gt; - The spacing between the sections. 

&lt;ul&gt;
&lt;li&gt;Takes a &lt;code&gt;Double&lt;/code&gt; value between 0 - 1.&lt;/li&gt;
&lt;li&gt;Applies percentage relative spacing.&lt;/li&gt;
&lt;li&gt;Default value is 0.05 (ie 5%).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ringWidth&lt;/code&gt; - The width of the rings. 

&lt;ul&gt;
&lt;li&gt;Default value is 10.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;roundedCap&lt;/code&gt; - Boolean denoting if the ends are rounded or not.

&lt;ul&gt;
&lt;li&gt;Default value is &lt;code&gt;true&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;centerFillColor&lt;/code&gt; - UIColor value representing the center fill color of the inner circle of the chart. 

&lt;ul&gt;
&lt;li&gt;Default value is &lt;code&gt;UIColor.clear&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once you are done making the changes you need to always call the method &lt;code&gt;reloadChart()&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So that's it, you just created a ring chart in &amp;lt;10 lines of code! 😎 If you have any comments or suggestions regarding improvements in the library or other additional functionality, you can drop a comment here or email me at &lt;a href="mailto:subhronilsaha99@gmail.com"&gt;subhronilsaha99@gmail.com&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;You can find the source code used in this article here:&lt;br&gt;
&lt;a href="https://github.com/subhronilsaha/CPRingChartExample"&gt;https://github.com/subhronilsaha/CPRingChartExample&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
      <category>chart</category>
      <category>cocoapod</category>
    </item>
    <item>
      <title>A Beginner's Guide to Swift Playgroundbooks</title>
      <dc:creator>Subhronil Saha</dc:creator>
      <pubDate>Wed, 21 Apr 2021 13:53:20 +0000</pubDate>
      <link>https://dev.to/subhronilsaha/a-beginner-s-guide-to-swift-playgroundbooks-4i5k</link>
      <guid>https://dev.to/subhronilsaha/a-beginner-s-guide-to-swift-playgroundbooks-4i5k</guid>
      <description>&lt;p&gt;For the past few years now, Apple has been conducting the &lt;strong&gt;WWDC Scholarship Program (now, WWDC Swift Student Challenge)&lt;/strong&gt;, which is a global challenge for students all across the globe, to showcase their love for coding by creating awesome projects related to any topic of their choice. &lt;/p&gt;

&lt;p&gt;Until a couple years ago, the winners of this challenge would receive free tickets for the annual event and get to fly to California to attend the Worldwide Developer Conference in person at San Jose Convention Center! 🤩&lt;/p&gt;

&lt;p&gt;However since 2020, due to Covid, Apple has made the whole event online and the winners would receive exclusive WWDC outerwear, a customized pin set and one year of membership in the Apple Developer Program. &lt;/p&gt;

&lt;p&gt;Many students still participate in this challenge every year, and this year I decided to give it a try myself!&lt;/p&gt;

&lt;p&gt;This year the challenge was to build an interactive Swift Playground Book that can be experienced in less than 3 minutes.&lt;/p&gt;

&lt;p&gt;So, the first question that came to my mind was ...&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I build a Swift Playground Book?
&lt;/h3&gt;

&lt;p&gt;You can build PlaygroundBooks in the Swift Playgrounds app (available for iPad and Mac) and also in Xcode. &lt;/p&gt;

&lt;h3&gt;
  
  
  Swift Playgrounds App
&lt;/h3&gt;

&lt;p&gt;First, go to the App Store, and look up Swift Playgrounds. The first result is usually the Swift Playgrounds app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hUGYVadE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/177h1hfzl259rfqlmfwq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hUGYVadE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/177h1hfzl259rfqlmfwq.png" alt="Swift Playgrounds on Mac App Store"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Download the app and open it.&lt;/p&gt;

&lt;p&gt;It should look something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tiMttB40--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kru4g6vh8nnbnfhwthp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tiMttB40--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kru4g6vh8nnbnfhwthp.png" alt="Swift Playgrounds app for Mac"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It shows a list of your previously imported books. I already had my playground book imported, but for you, this screen may be blank.&lt;/p&gt;

&lt;p&gt;If you click on the 'See All' button at the bottom right, it should show you a page with a lot of templates that you can use to build your project on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jIcORvLz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ukpy3sz0vd7rxhgsao5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jIcORvLz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ukpy3sz0vd7rxhgsao5.png" alt="More Playgrounds"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this tutorial, we will use the &lt;strong&gt;Xcode Playground&lt;/strong&gt; template. &lt;/p&gt;

&lt;p&gt;Click on it from the list of templates under the &lt;strong&gt;Starting Points&lt;/strong&gt; section. &lt;/p&gt;

&lt;p&gt;It will add the Xcode Playground template to your list of imported books.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b-FpX7dt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/di8zv3lm8fe2kxc7rcmj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b-FpX7dt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/di8zv3lm8fe2kxc7rcmj.png" alt="Screen Shot 2021-04-21 at 6.22.21 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click to open it.&lt;/p&gt;

&lt;p&gt;This is how a your playground book will look like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4G--wSbV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifub3jdnnewh0y23yuuc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4G--wSbV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ifub3jdnnewh0y23yuuc.png" alt="Screen Shot 2021-04-21 at 6.32.40 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will only see a blank editor for now.&lt;/p&gt;

&lt;p&gt;The typical structure of a PlaygroundBook is as follows.&lt;/p&gt;

&lt;p&gt;The PlaygroundBook is divided into Chapters, each of which contains some Pages.&lt;/p&gt;

&lt;p&gt;If you look at your screen now, on your left, you will see a list of &lt;strong&gt;Pages&lt;/strong&gt;, grouped into &lt;strong&gt;Chapters&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Each playground page is divided into 2 halves. &lt;/p&gt;

&lt;p&gt;On the left side, you can add text and code that you want to execute.&lt;/p&gt;

&lt;p&gt;The code you type on the left will run on the right side of the page. The right side of the page is called the &lt;strong&gt;Live View.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Initially, there is no Live View.&lt;/p&gt;

&lt;p&gt;To initialize it, type the following code into the editor. We will be using SwiftUI for building this Playground.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import SwiftUI
import PlaygroundSupport

struct ContentView: View {
    var body: some View {
        Text("Hello World")
    }
}

PlaygroundPage.current.setLiveView(ContentView())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hit the &lt;strong&gt;Run My Code&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;Your screen should look something like this now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fiw81pBS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5vwkrfpu9u7t2qzqw0h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fiw81pBS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5vwkrfpu9u7t2qzqw0h.png" alt="Screen Shot 2021-04-21 at 6.39.18 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Essentially, what we did just now is that we made a SwiftUI view named &lt;strong&gt;ContentView&lt;/strong&gt;, and then we set it as the live view of our current playground page.&lt;/p&gt;

&lt;p&gt;And as you can see, our SwiftUI view (with the text &lt;em&gt;"Hello World"&lt;/em&gt;) is being displayed on the right of the page! Awesome. 😀   &lt;/p&gt;

&lt;p&gt;If you know SwiftUI then you will be able to build awesome stuff from here on out. You can also try out the other templates provided in Swift Playgrounds and play around &amp;amp; build something awesome.&lt;/p&gt;

&lt;p&gt;If you want to customize your playground book even more, like add a book cover, you should go probably use a Swift PlaygroundBook Author template and modify it using Xcode.&lt;/p&gt;

&lt;p&gt;I will be writing an article about Swift PlaygroundBook Author Template in my next post, so if you want to know more about it, do check it out.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>swift</category>
      <category>playgrounds</category>
      <category>apple</category>
      <category>swiftui</category>
    </item>
  </channel>
</rss>
