Nitin Aggarwal has Published 156 Articles

Swift optional escaping closure parameter

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:59:11

942 Views

In Swift, an optional escaping closure parameter is a closure that can be executed after the function it is passed to has returned. In this article, we will see how to create escaping closures as parameters with examples. To declare an optional escaping closure parameter, you add the @escaping keyword ... Read More

Swift integer conversion to Hours/Minutes/Seconds

Nitin Aggarwal

Nitin Aggarwal

Updated on 04-May-2023 12:56:36

2K+ Views

In Swift, there are many approaches to converting an integer to time components like hours, minutes, and seconds. Every approach depends on the requirement. For example, you can use arithmetic operators to convert. Another approach is using DateComponentsFormatter class to convert an integer into time components easily. In this article, ... Read More

Swift do-try-catch syntax and implementation

Nitin Aggarwal

Nitin Aggarwal

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

3K+ 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

989 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

2K+ 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

992 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

2K+ 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

2K+ 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

1K+ 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

572 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

Advertisements