Nitin Aggarwal has Published 134 Articles

Swift do-try-catch syntax and implementation

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:54:20

4K+ Views

In Swift, the do-try-catch statement is used to handle errors that can be thrown by a function or method. It provides a structured way to catch and handle errors in your code. In your codebase, you cannot handle all runtime errors when they come but using try-catch you can handle ... Read More

Is key-value observation (KVO) available in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:51:22

1K+ Views

In Swift, you can use KVO to observe changes to an object property by registering an observer for that property. When the property value changes, the observer is notified and can take appropriate actions. In this article, you will see an example of how to implement KVO in Swift. To ... Read More

How to save local data in a Swift app?

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:49:42

3K+ Views

In Swift, there are several ways to save local data in an app, depending on the type and size of data you want to save. You can use User Defaults, Property List Serialization, Core Data, etc. In this article, you will learn about User Defaults with some examples. User Defaults ... Read More

How to manually deprecate members in iOS Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:48:01

2K+ Views

In iOS Swift, you can manually deprecate members (properties, methods, and other members) by using the @available attribute with the deprecated argument. @available The @available attribute in Swift is used to specify the availability of a particular piece of code. It can be used to mark a class, function, method, ... Read More

How to create an empty array in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:45:15

4K+ Views

In Swift, there are several ways to create an empty array. All approaches are very easy to create an array. Manytimes, creating an empty array is most common requirement in your apps. You can create empty array of any type. In this article, you will see different ways to construct ... Read More

How to call tap gestures on UIView programmatically in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:44:07

4K+ Views

In Swift, you can use the UITapGestureRecognizer class to add a tap gesture on view programmatically. This class provides you with different properties and methods to enable a tap gesture. In this article, you will learn how to add a tap gesture with an example. UITapGestureRecognizer class UITapGestureRecognizer is a ... Read More

Why do I need underscores in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:35:08

3K+ Views

In Swift, underscores have many different uses for a different purposes. Here are some examples. Ignore unnecessary loop variables or return values. Absence of identifiers for external parameters in function calls. Even if they were initially specified as constants, making variables changeable. Ignoring tuple components or using discard values ... Read More

What's the cleanest way of applying map() to a dictionary in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:32:50

1K+ Views

In Swift, we can use the map() method to the dictionary to apply a transformation to the values of the dictionary. This method returns a newly created object with the same keys as the original dictionary but with the values transformed by the mapping function. Example 1: Transforming Values with ... Read More

What's the best practice for naming Swift files that add extensions to existing objects?

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:30:28

1K+ Views

There is no single "best" practice for naming Swift files that add extensions to existing objects, but here are some commonly used conventions − Object Prefix Followed by Functionality String+Utilities.swift − adds utility functions to the String class Array+Sorting.swift − adds sorting functions to the Array class UIColor+Extensions.swift − ... Read More

Swift: declare an empty dictionary

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:26:54

265 Views

In Swift, there are some different syntaxes to declare an empty dictionary. It is important to remember that all syntaxes produce the same result. In this article, you will see examples of how to declare an empty dictionary and define a dictionary in Swift. What is a Swift Dictionary? A ... Read More

Advertisements