Oh my Swift
Archives Newsletter Social media App Showcase
  • How to add a loader to an UIButton

    Aug 28, 2022 • UIButton • add loader to an uibutton, swift, UIButton, iOS15, UIButtonConfiguration, ios15 button configuration, swift ios 15, customizing uibutton in swift, swift uibutton, implementing button in swift

    Sometimes, we would require a button to show a loader with appropriate text when a long-duration task is done, such as downloading an image. Before iOS 15, we had to write a custom button or do some hacks to show a simple loader or an UIActivityIndicator inside an UIButton. Now, it is not the case anymore. UIButtonConfiguration provides showsActivityIndicator, a simple property using which we can hide/show a loader inside a button.

    Read on →

  • How to filter screenshots, cinematic videos, and depth-effect photos in PHPickerViewController

    Jun 26, 2022 • PHPickerViewController • swift, imageassets, phphotopickerviewcontroller, uiimagepikcercontroller, images, phpicker, photolibrary

    In iOS 14.0, Apple introduced a new way to pick images from the device’s photo library using PHPickerViewController. (If you are not aware of PHPickerViewController, I strongly recommend you to read about PHPickerViewController first.)

    Read on →

  • Implementing a custom native calendar using UICalendarView in iOS16 and Swift

    Jun 12, 2022 • UIKit • swift, UICalendarView, FSCalendar, customize calendar in iOS16, iOS 16, calendar view, single select calendar, multi select calendar, swift calendar implementation

    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 😜 .”

    Read on →

  • Different methods to remove the last item from an array in Swift

    Apr 24, 2022 • Array • swift, UIButton, iOS15, remove array elements, iOS 16, swift ios 15, droplast in swift, removeLast in swift, how to remove element from an array

    Arrays are one of the most widely used data structures in Swift, and we deal with a lot of array manipulations. One such manipulation is the removal of the last element from an array. The three useful methods to remove an element from an array are dropLast(), popLast(), and removeLast()

    Read on →

  • Customizing UIButton in iOS 15

    Aug 23, 2021 • UIButton • swift, UIButton, iOS15, UIButtonConfiguration, ios15 button configuration, swift ios 15, customizing uibutton in swift, swift uibutton, implementing button in swift

    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. 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. Let’s get started!

    Read on →

  • Exploring Deque in Swift Collections

    Apr 14, 2021 • Deque • swift, swift ordered dictionary, swift collections, swift deque, swift deque collections, swift ordered set, swift arrays, deque vs arrays, swift deque vs swift arrays

    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.

    Read on →

  • Swap keys and values of a Dictionary

    Mar 24, 2021 • Dictionary • swift, swift dictionary, dictionary

    Dictionaries are one of the most commonly used data structures. Dictionaries come with keys and values where the keys are unique. Sometimes, there might be a situation where we would want to swap the keys and values of a dictionary. Let’s see how to swap keys and values of a dictionary in swift.

    Read on →

  • Experimenting with Swift async and await pattern using Xcode

    Dec 25, 2020 • Concurrency • swift async await, async/await swift, concurrency in swift, swift concurrency, async await, async await swift5

    You all might know that async/await is accepted and is available in the main snapshots! Let’s get our hands dirty by trying out some basic example of async/await in Swift.

    Read on →

  • Common problems and workarounds while building apps using Apple Silicon

    Dec 19, 2020 • Apple Silicon • apple silicon, cocoapods, cocoapods apple silicon, cocoapods not installing in apple silicon, firebase, firebase not building in apple silicon, firebase in apple silicon, firebase apple silicon, m1 processor, apple silicon project not building

    Apple’s new Apple Silicon (M1 processor) is a beast. The apps open pretty quickly, and the slow Xcode build times are a thing of the past. But what does it have in store for the iOS/macOS developers?

    Read on →

  • Closure based actions in UIButton

    Nov 1, 2020 • UIButton • swift, uibutton closure, closure, closure uibutton, callbacks closure, closure callbacks

    iOS 14.0 brings us many improvements and new APIs using which the developers can write efficient code. One such API is the closure based action API instead of the addTarget method in UIControls. Yes, you heard me right—no more usage of addTarget methods, #selector(), and @objc annotation in front of methods. More importantly, we can write a closure based code using the action handler. Okay, enough talk, let’s dive into the code.

    Read on →

  • Replacing UIImagePickerController with PHPickerViewController

    Aug 29, 2020 • PHPickerViewController • swift, imageassets, phphotopickerviewcontroller, uiimagepikcercontroller, images

    Almost every app requires photos and video access these days. Before iOS 14.0, the iOS developers used UIImagePickerController to access the items from the user’s media library. From iOS 14.0, Apple is providing its developers a brand new way to select images or videos from their apps using PHPickerViewController

    Read on →

  • Embracing Localization in Image Assets

    Jun 14, 2020 • XCAssets • swift, imageassets, localization, image localization

    One of the most significant features which make an app stand out is localization. When we hear the term localization, the first thing that comes to mind is localizing the text displayed in UILabels, UITextViews, UIButtons, and other UIElements. It is quite straight forward to localize the text in the UIElements, and most of us think that we have localized the app, and it is ready to go! But wait, there is one more area I would like to highlight, and that is the images used in the app. You heard me right. If the images used in the app contain text, then they should be localized as well. Localizing the image assets is slightly different but not so hard.

    Read on →

  • An effective way to clear entire Userdefaults in Swift

    May 19, 2020 • Userdefaults • swift, userdefaults

    As a developer, we might use Userdefaults in our apps at some point in time for storing some basic configuration or settings in the app. But as the project gets complex, things can get pretty tough. Especially, when you want to clear all the UserDefaults values from the app. Well, we can use the removeObject method to remove the value for a particular key.

    Read on →

  • Using UICollectionViewCompositionalLayout in iOS 12 and earlier

    Mar 18, 2020 • UICollectionView • Swift, uicollectionview, uicollectionviewcompositionallayout, collection view, compositional layouts

    At WWDC 2019, Apple added a brand new API “UICollectionViewCompositionalLayout” to the UIKit. Using this powerful API, we can create complex compositional layouts without writing complicated code. At times, It feels tough to create complex collection view UIs using the UICollectionViewFlowLayout. The UICollectionViewCompositionalLayout API eases the process and guess what you can even support orthogonal scrolling UIs with much ease. Well, it sounds great, but practically we cannot use the UICollectionViewCompositionalLayout API until we drop the support for iOS 12.0 and earlier in our apps. (It is not going to happen for the next few years is what I predict.) So how do we use this API in iOS 12.0 and earlier?

    Read on →

  • Simulating remote push notifications in a simulator

    Feb 13, 2020 • Push Notifications • swift, ios simulator, simulator notifications

    Apple just released Xcode 11.4 beta with tons of features. One of the notable features is simulating remote push notifications in simulators, which means that triggering remote notifications in simulators is now possible.

    Read on →

  • Why should we avoid using closures in Swift structs?

    Jan 10, 2020 • Closures • swift, struct, closures, struct vs classes

    We all love closures, don’t we? Closures make an iOS developer’s life easy. Well, if it makes it easy, then why am I saying to avoid using closures in Swift structs? The reason is, “Memory leaks and unexpected behaviors.” Wait. What? Memory leak in structs? How could that be possible?

    Read on →

  • Swift 5 replaces IntroSort with TimSort in the 'sort()' method

    Sep 29, 2019 • Algorithms • swift, timsort, algorithms, sort

    When we hear the term ‘Sorting,’ the algorithms which come to our mind are quicksort, insertion sort, merge sort, bubble sort, heap sort, and other sorting algorithms. We would have used the method sort() to sort elements in an array, in our day to day programming tasks. However, have you ever wondered what algorithm does the method uses to sort the items in Swift? Before Swift 5, it was ‘Introsort,’ but after Swift 5, it is ‘Timsort.’ Timsort is a sorting algorithm, used in programming languages like Python, and Java. I am going to cover mostly about ‘Timsort’ in this article.

    Read on →

  • Generate URLSession code in Swift using Postman

    Sep 18, 2019 • Postman • swift, postman

    Almost every iOS developer would have had to make a network call from their app. Swift uses URLSession to make network calls. URLSessionTask includes DataTask, UploadTask, DownloadTask, and WebsocketTask (WebsocketTask is lately introduced in iOS13.0 check this article to know more about it.) I was testing a multipart data request API using the [Postman app.]https://www.getpostman.com/ The API worked, the file got uploaded, and the results came in. However, I needed to write the Swift code to make a multipart request from the iOS app. Writing code for data task can be simple, but the complexity increases when we write code for multipart requests. I was wondering whether Postman can generate the multipart data request code for me, turns out that it could!

    Read on →

  • Introducing URLSessionWebSocketTask - Native WebSocket implementation using Swift 5

    Aug 31, 2019 • URLSession • swift, iOS, websockets, URLSessionWebSocketTask

    We all love WebSockets, don’t we? They have a vast range of applications such as chat applications, push notifications, and much more. I got excited when I stumbled upon “URLSessionWebSocketTask”. That’s right, in addition to data task, download task, and upload task, we have websocketTask! in URLSession. Websockets are now first-class citizens in the foundation framework. Before websocket tasks, we had to use third-party libraries like Star Scream or Socket Rocket, but it is not the case anymore.

    Read on →

  • Swift bit #4 - Swifty ways of typecasting objects

    Aug 27, 2019 • Swift fundamentals • swift, iOS, type casting

    Often we find ourselves in a situation where we need to check whether an object belongs to a particular class or not. For example, consider there is a UIView, and there are many subviews like UITextView, UILabel, and UIStepper. Now you have to find the UILabel from the parent view and change its text value. So how do we do that? Well, there are multiple ways of doing it.

    Read on →

« Older

© - Powered by Jekyll & whiteglass - Subscribe via RSS

Ohmyswift is hosted at HostPalace