<?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: Rizwan Ahmed</title>
    <description>The latest articles on DEV Community by Rizwan Ahmed (@rizwan95).</description>
    <link>https://dev.to/rizwan95</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%2F410831%2Fd755a29e-a35e-4b6a-ac30-2119dfa7ee0c.jpeg</url>
      <title>DEV Community: Rizwan Ahmed</title>
      <link>https://dev.to/rizwan95</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rizwan95"/>
    <language>en</language>
    <item>
      <title>Send data Between iOS Apps and Extensions Using Darwin Notifications</title>
      <dc:creator>Rizwan Ahmed</dc:creator>
      <pubDate>Wed, 28 Aug 2024 05:22:06 +0000</pubDate>
      <link>https://dev.to/rizwan95/send-data-between-ios-apps-and-extensions-using-darwin-notifications-o70</link>
      <guid>https://dev.to/rizwan95/send-data-between-ios-apps-and-extensions-using-darwin-notifications-o70</guid>
      <description>&lt;p&gt;In iOS development, app extensions run in separate processes from their containing apps. This separation poses a challenge when you need to communicate between the main app and its extensions. While &lt;code&gt;NSNotificationCenter&lt;/code&gt; is a common choice for passing data between view controllers within the same app, it falls short when it comes to inter-process communication. Have you ever thought about how to pass data between the main app and its extension? Darwin notifications provide a powerful solution for this scenario. In this post, we'll explore how to implement a Darwin Notifications manager and use it to facilitate real-time data transfer between a main app and its extension.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Darwin Notifications a.k.a CFNotificationCenterGetDarwinNotifyCenter?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;CFNotificationCenterGetDarwinNotifyCenter&lt;/code&gt; is a function in Apple's Core Foundation framework that provides access to the Darwin Notification Center. This notification center is designed for system-wide notifications, allowing different processes (such as your app and its extensions) to communicate with each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does it Work?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;System-Wide Communication:&lt;/strong&gt; Unlike NSNotificationCenter, which is limited to the app's process, the Darwin Notification Center can send notifications that can be observed by other processes on the device. This makes it ideal for app-to-extension communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No UserInfo Dictionary:&lt;/strong&gt; One limitation is that Darwin notifications do not support sending additional data (like a userInfo dictionary). This means you can only send a simple notification without any extra information. This is because the underlying mechanism, notify_post(), only accepts a string identifier for the notification&lt;/p&gt;

&lt;h2&gt;
  
  
  A use case for Darwin Notifications
&lt;/h2&gt;

&lt;p&gt;For example, when a broadcast upload extension starts or stops, you can use a Darwin notification to inform the main app. I have seen most of the people use UserDefaults or the Keychain but I personally feel that Darwin notifications are the best fit for this use case. &lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing the Darwin Notification Manager
&lt;/h2&gt;

&lt;p&gt;To start, we'll create a &lt;code&gt;DarwinNotificationManager&lt;/code&gt; class that uses the &lt;code&gt;CFNotificationCenter&lt;/code&gt; API to post and observe notifications across processes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;Foundation&lt;/span&gt;

 &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;DarwinNotificationManager&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;shared&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;DarwinNotificationManager&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;


    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;callbacks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Void&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[:]&lt;/span&gt;

    &lt;span class="c1"&gt;// Method to post a Darwin notification&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;postNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;notificationCenter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;CFNotificationCenterGetDarwinNotifyCenter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="kt"&gt;CFNotificationCenterPostNotification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;notificationCenter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;CFNotificationName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;CFString&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;startObserving&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;@escaping&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;callback&lt;/span&gt;

        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;notificationCenter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;CFNotificationCenterGetDarwinNotifyCenter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="kt"&gt;CFNotificationCenterAddObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;notificationCenter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                        &lt;span class="kt"&gt;Unmanaged&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;passUnretained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toOpaque&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
                                        &lt;span class="kt"&gt;DarwinNotificationManager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notificationCallback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                        &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;CFString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                        &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;deliverImmediately&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;stopObserving&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;notificationCenter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;CFNotificationCenterGetDarwinNotifyCenter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="kt"&gt;CFNotificationCenterRemoveObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;notificationCenter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Unmanaged&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;passUnretained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toOpaque&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="kt"&gt;CFNotificationName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;CFString&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;forKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;


    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;notificationCallback&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;CFNotificationCallback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;center&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
        &lt;span class="k"&gt;guard&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;observer&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Unmanaged&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;DarwinNotificationManager&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromOpaque&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;takeUnretainedValue&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rawValue&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?,&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;callback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;callback&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To understand more about Darwin Notifications, please refer to the original article: ‘Sending Data Between iOS Apps and Extensions Using Darwin Notifications’ available at this link: &lt;a href="https://ohmyswift.com/blog/2024/08/27/send-data-between-ios-apps-and-extensions-using-darwin-notifications/" rel="noopener noreferrer"&gt;https://ohmyswift.com/blog/2024/08/27/send-data-between-ios-apps-and-extensions-using-darwin-notifications/&lt;/a&gt;&lt;/p&gt;

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

</description>
      <category>ios</category>
      <category>swift</category>
    </item>
    <item>
      <title>Implementing a custom native calendar using UICalendarView in iOS16 and Swift</title>
      <dc:creator>Rizwan Ahmed</dc:creator>
      <pubDate>Sun, 10 Jul 2022 06:19:21 +0000</pubDate>
      <link>https://dev.to/rizwan95/implementing-a-custom-native-calendar-using-uicalendarview-in-ios16-and-swift-3gec</link>
      <guid>https://dev.to/rizwan95/implementing-a-custom-native-calendar-using-uicalendarview-in-ios16-and-swift-3gec</guid>
      <description>&lt;p&gt;It was WWDC22 week, and I was browsing through my Twitter feed to get some updates about the latest Apple APIs. A person tweeted, “No matter how experienced you are as an iOS developer, you’ll always look it up how to set up a date formatter.” So I humorously replied to the tweet by saying, “Dates are hard 😜 .”&lt;/p&gt;

&lt;p&gt;After a while, something struck my mind, and I was curious to know if Apple had made improvements to the existing date picker. To my surprise, Apple introduced UICalendarView to create custom calendar views from iOS 16.&lt;/p&gt;

&lt;p&gt;At that moment, I could realize how easy it would become for an iOS developer to implement and customize calendar views. Previously, we used third-party calendar components, which came with issues and bugs. Let’s see how to implement a custom native calendar using UICalendarView in iOS 16 and Swift.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up UICalendarView
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fznw807gctoqpt3jvjr6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fznw807gctoqpt3jvjr6d.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;UICalendarView belongs to the UIKit framework and comes with a simple initializer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let calendarView = UICalendarView()
let gregorianCalendar = Calendar(identifier: .gregorian)
calendarView.calendar = gregorianCalendar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Apple tells us that it is necessary to mention the calendar type explicitly while creating a UICalendarView object. In our example, it will be gregorian calendar.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API availablility:&lt;/strong&gt; UICalendarView is available from iOS16.0+, iPadOS16.0+, and macCatalyst16.0+&lt;/p&gt;

&lt;h2&gt;
  
  
  Customizing UICalendarView
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgjyq0jwbhe91vk8icbb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgjyq0jwbhe91vk8icbb.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;UICalendarView supports various customizations like setting the background color, setting the view’s corner radius, changing the calendar’s tint color, and many more.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;calendarView.backgroundColor = .secondarySystemBackground
calendarView.layer.cornerCurve = .continuous
calendarView.layer.cornerRadius = 10.0
calendarView.tintColor = UIColor.systemTeal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For further reading visit &lt;a href="https://ohmyswift.com/blog/2022/06/12/implementing-a-custom-native-calendar-using-uicalendarview-in-ios16-and-swift/" rel="noopener noreferrer"&gt;https://ohmyswift.com/blog/2022/06/12/implementing-a-custom-native-calendar-using-uicalendarview-in-ios16-and-swift/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>uicalendarview</category>
    </item>
    <item>
      <title>Customizing UIButton in iOS 15</title>
      <dc:creator>Rizwan Ahmed</dc:creator>
      <pubDate>Tue, 24 Aug 2021 09:52:17 +0000</pubDate>
      <link>https://dev.to/rizwan95/customizing-uibutton-in-ios-15-3d1m</link>
      <guid>https://dev.to/rizwan95/customizing-uibutton-in-ios-15-3d1m</guid>
      <description>&lt;p&gt;Buttons are an essential element in iOS apps. If you are developing an app using UIKit, you will probably use UIButton class to create buttons. &lt;br&gt;
Creating a button is a straightforward process, but it becomes problematic when it comes to customizations. Soon you will find yourself writing hacks for achieving your desired result. We all have been there, and we have done it. You are not alone. Luckily, iOS 15.0 gives us a new method to customize Buttons much easier using UIButton.Configuration.&lt;br&gt;
Let's get started!&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuration types in UIButton
&lt;/h2&gt;

&lt;p&gt;UIButton.Configuration comes in four different types, namely plain, filled, gray, and tinted. &lt;br&gt;
In this article, we will be focusing only on filled configuration. I will leave the rest of the configurations for you to experiment.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var configuration = UIButton.Configuration.filled()&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting a title in a UIButton
&lt;/h2&gt;

&lt;p&gt;Setting a title is done by using the configuration's title property.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;configuration.title = "Start download"&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IXjo8ZBL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/title.png%3Fstyle%3Dcenterme" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IXjo8ZBL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/title.png%3Fstyle%3Dcenterme" alt="Setting a title in a UIButton"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting a subtitle in a UIButton
&lt;/h2&gt;

&lt;p&gt;Again, we can make use of the configuration's subtitle property to set a subtitle. It would be tough to set a subtitle without the configuration API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;configuration.subtitle = "(Downloads a random image)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_UBuh-1x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/subtitle.png%3Fstyle%3Dcenterme" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_UBuh-1x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/subtitle.png%3Fstyle%3Dcenterme" alt="Setting a subtitle in a UIButton"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting an image in a UIButton
&lt;/h2&gt;

&lt;p&gt;Adding an image to the button and customizing it has become effortless. An important point to note here is that, the image respects the language's direction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;configuration.image = UIImage(systemName: "arrow.down.square.fill")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ajvjgpoZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/button-image.png%3Fstyle%3Dcenterme" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ajvjgpoZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/button-image.png%3Fstyle%3Dcenterme" alt="Setting an image in a UIButton"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Padding between an image and a title in a UIButton
&lt;/h2&gt;

&lt;p&gt;The UIButton configuration makes it easy to set a padding between the image and the button's&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;configuration.imagePadding = 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OhVwOnY7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/image-padding.png%3Fstyle%3Dcenterme" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OhVwOnY7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/image-padding.png%3Fstyle%3Dcenterme" alt="Padding between an image and a title in a UIButton"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Changing the position of an image in a UIButton
&lt;/h2&gt;

&lt;p&gt;The imagePlacement is my favorite property. I have written so many nasty hacks for just changing the position of the image in a UIButton, before iOS 15.0&lt;br&gt;
The imagePlacement property supports the following options - leading, trailing, top, or bottom.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;configuration.imagePlacement = .trailing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iICX4Tps--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/button-image-position.png%3Fstyle%3Dcenterme" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iICX4Tps--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ohmyswift.com/blog/assets/images/customize-uibutton-ios15/button-image-position.png%3Fstyle%3Dcenterme" alt="Changing the position of an image in a UIButton"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ohmyswift.com/blog/2021/08/23/customizing-uibutton-in-ios-15/"&gt;This article was originally published at ohmyswift.com. Click here to read the full article.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  About the author 👨‍💻
&lt;/h3&gt;

&lt;p&gt;Rizwan Ahmed — iOS Engineer. &lt;br&gt;
Twitter 👉 &lt;a href="https://twitter.com/rizwanasifahmed"&gt;https://twitter.com/rizwanasifahmed&lt;/a&gt;&lt;br&gt;
Like our articles? Support us 👉&lt;a href="https://www.buymeacoffee.com/ohmyswift"&gt;https://www.buymeacoffee.com/ohmyswift&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>uibutton</category>
      <category>ios15</category>
      <category>customizinguibutton</category>
    </item>
    <item>
      <title>Exploring Deque in Swift Collections</title>
      <dc:creator>Rizwan Ahmed</dc:creator>
      <pubDate>Thu, 15 Apr 2021 11:54:11 +0000</pubDate>
      <link>https://dev.to/rizwan95/exploring-deque-in-swift-collections-1f9f</link>
      <guid>https://dev.to/rizwan95/exploring-deque-in-swift-collections-1f9f</guid>
      <description>&lt;p&gt;Deque (should be pronounced as "deck") is a collection implementing double-ended queues. Deques are similar to arrays, but they have efficient insertions and removal of elements at the beginning and at the end. &lt;/p&gt;

&lt;p&gt;The indexing semantics are integer indices that are the same as arrays. &lt;br&gt;
Now let's see a sample implementation of deque.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var colors: Deque = ["Yellow", "Orange"]
print(colors) // [Yellow, Orange]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code implements a deque of colors with the strings yellow and orange. &lt;/p&gt;

&lt;h2&gt;
  
  
  Deque operations
&lt;/h2&gt;

&lt;p&gt;Now let's see some operations or methods unique to deques. &lt;/p&gt;

&lt;h4&gt;
  
  
  1. prepend - Adding an element at the beginning of the deque.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;colors.prepend("Blue") // Blue is added to the beginning
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2.  append - Adding an element to the end of the deque.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;colors.append("White") // White is added to the end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. popFirst - Removal of an element from the beginning of the deque.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let _ = colors.popFirst() // Blue is removed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. popLast - Removal of an element from the beginning of the deque.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let _ = colors.popLast() // White is removed
print(colors) // [Yellow, Orange]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://ohmyswift.com/blog/2021/04/14/exploring-deque-in-swift-collections/"&gt;This article was originally published at ohmyswift.com. Click here to read the full article.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  About the author 👨‍💻
&lt;/h3&gt;

&lt;p&gt;Rizwan Ahmed — iOS Engineer. &lt;br&gt;
Twitter 👉 &lt;a href="https://twitter.com/rizwanasifahmed"&gt;https://twitter.com/rizwanasifahmed&lt;/a&gt;&lt;br&gt;
Like our articles? Support us 👉&lt;a href="https://www.buymeacoffee.com/ohmyswift"&gt;https://www.buymeacoffee.com/ohmyswift&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>swiftdeque</category>
      <category>dequesinswift</category>
      <category>swiftarrays</category>
    </item>
  </channel>
</rss>
