Nitin Aggarwal has Published 156 Articles

Why is the Convenience Keyword Even Needed in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 11:30:08

455 Views

In Swift, you can create an additional initializer to provide default values for the properties. You can use the convenience keyword to add this functionality. Let's look at some examples of how to use a convenience initializer in the Swift language. What is a convenience initializer in Swift? In Swift, ... Read More

What's the equivalent of NSLocalizedString in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 11:27:26

390 Views

In real iOS applications, you often need to support localization to ensure the app's accessibility around the world. By incorporating localization into your app, you can gain more users. In Swift, we use the NSLocalizedString function to create a localized string. What is localization? Localization is the process of allowing ... Read More

What is the most succinct way to remove the first character from a string in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 11:18:36

304 Views

In Swift, we can use methods like dropFirst, Index(after:), and many others that can remove the first character of a string. In this article, we are going to learn various examples of these functions and understand how can we remove the first character of a string. Using the dropFirst method ... Read More

Swift: Pass an array by reference?

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 11:14:18

3K+ Views

In Swift, you can pass an array by reference in a function as an argument using inout keyword. In Swift, arrays are value types by default. In other words, they pass a value rather than a reference. If you pass an array to a function as an argument, it makes ... Read More

Swift JSONDecode decoding arrays fail if single element decoding fails

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 11:09:18

156 Views

In Swift, working with JSON objects is very easy with the JSONDecoder class. It is always necessary to create model classes or structs with the Codable protocol. One single mistake leads you to fail to decode the complete JSON object. Let's explore some examples to understand when this failure might ... Read More

Overriding a superclass property with a different type in Swift

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 11:05:37

981 Views

We can define a subclass that is inherited from a superclass in the Swift language, That means you can override its properties and methods using the override keyword. However, you cannot override the properties with a different type in the subclass. By default, the subclass must override the properties of ... Read More

Objective-C and Swift URL encoding

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 11:01:18

2K+ Views

URL encoding is an essential part of iOS app development. Many times, you will need to encode the URL to communicate with servers. Let's look at some examples of how you can encode an URL in Swift and Objective-C. URL Encoding in Swift In Swift, you can use the addingPercentEncoding(withAllowedCharacters:) ... Read More

New Array from Index Range Swift

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 10:53:41

619 Views

In Swift, you can create an array using the ArraySlice type. The following examples will show how to use the ArraySlice type. You can create an extension as well to define the subscript method. Example 1 In the following example, we create an array of numbers with values from 0 ... Read More

Multiple Type Constraints in Swift

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 10:50:39

762 Views

In Swift, there are several ways to implement type constraints on types. We will use some common approaches like the where clause, protocol, etc. Generics provide lots of flexibility to write better and more secure code in Swift. We can apply generics to collections, custom types, etc. One of them ... Read More

How to assign an action to the UIImageView object in Swift?

Nitin Aggarwal

Nitin Aggarwal

Updated on 11-Apr-2023 10:46:08

979 Views

In the iOS applications, the UIImageView class does not provide in-build support to make it clickable like other components e.g. UIButton. In order to make UIImageView clickable, you can add a UITapGestureRecognizer to the image view. Remember that, by default, UIImageView does not take any interaction from the user. To ... Read More

Previous 1 ... 4 5 6 7 8 ... 16 Next
Advertisements