Found 33676 Articles for Programming

How to create an empty array in Swift?

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 an empty array. Syntax In Swift, you can create an empty array of a certain type using the following syntax − var arrayName = [Type]() Or you can use this alternate syntax − var arrayName: [Type] = [] Both syntaxes work similarly in Swift. For example, if you ... Read More

How to call tap gestures on UIView programmatically in Swift?

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 built-in class in the UIKit framework that recognizes a tap gesture on a view. A tap gesture is a quick touch with a single finger or multiple fingers on the screen. UITapGestureRecognizer recognizes taps of a certain number of fingers, taps a certain number of times, and a combination of ... Read More

C# Program to Sort a List of String Names Using the LINQ OrderBy() Method

Sabid Ansari
Updated on 04-May-2023 14:10:54

2K+ Views

Sorting a list of string names is a common task in programming, and the LINQ OrderBy() method in C# provides an easy and efficient way to do so. In this article, we will walk you through a C# program to sort a list of string names using the LINQ OrderBy() method. What is LINQ OrderBy() Method? The LINQ OrderBy() method is used to sort the elements of a sequence in ascending or descending order based on one or more keys. The keys can be simple properties or complex expressions that return a value based on one or more properties of ... Read More

C# Program to Sort a List of Integers Using the LINQ OrderBy() Method

Sabid Ansari
Updated on 04-May-2023 14:09:52

2K+ Views

Sorting a list of integers is a common task in programming, and the LINQ OrderBy() method in C# provides an easy and efficient way to do so. In this article, we'll walk you through a C# program to sort a list of integers using the LINQ OrderBy() method. What is LINQ OrderBy() Method? The LINQ OrderBy() method is used to sort the elements of a sequence in ascending or descending order based on one or more keys. The keys can be simple properties or complex expressions that return a value based on one or more properties of the objects in ... Read More

C# Program to Sort a List of Employees Based on Salary using LINQ

Sabid Ansari
Updated on 04-May-2023 14:08:34

1K+ Views

In many software development projects, there comes a point where it becomes necessary to sort a list of objects based on one or more properties of the objects. In C#, the LINQ (Language Integrated Query) library provides a powerful and easy-to-use way to sort lists of objects based on one or more criteria. In this tutorial, we will demonstrate how to sort a list of Employee objects based on their salary using LINQ. Steps Create an Employee class with properties for Name, Salary, and Department. Create a List of Employee objects and populate it with some data. Use LINQ ... Read More

C# Program to Sort a List of Employees Based on Salary in Descending Order and Whose Department is XYZ using LINQ

Sabid Ansari
Updated on 04-May-2023 14:06:29

411 Views

In C#, LINQ (Language Integrated Query) is a powerful tool that enables you to easily sort, filter, and manipulate data. In this article, we'll demonstrate how to use LINQ to sort a list of employees based on their salary in descending order and department in which they work. Sorting a List of Employees Based on Salary in Descending Order and Whose Department is XYZ using LINQ − To sort a list of employees based on their salary in descending order and department using LINQ, you can follow the steps below − Create a class to represent an Employee − ... Read More

Why do I need underscores in Swift?

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 when managing errors. To Ignore a Value To ignore a value that a function or method returns in Swift, use an underscore. You could compose something like this, for instance, if you only worry about an operation's success or failure. This is the most common case you use in ... Read More

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

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

969 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 a Closure In the following example, we are performing the multiplication on each value in the dictionary using the mapValues() function. We pass a closure that takes an argument. In the resulting dictionary, you can see that each value has been doubled. import Foundation let inputDictionary = [1: 2, 3: ... Read More

C# Program to Sort a List of Employees Based on Salary and Whose Department is ABC using LINQ

Sabid Ansari
Updated on 04-May-2023 14:04:27

945 Views

In C#, LINQ (Language Integrated Query) is a powerful tool that enables you to easily sort, filter, and manipulate data. In this article, we'll demonstrate how to use LINQ to sort a list of employees based on their salary and department. Sorting a List of Employees Based on Salary and Department using LINQ To sort a list of employees based on their salary and department using LINQ, you can follow the steps below − 1. Create a Class to Represent an Employee public class Employee { public string Name { get; set; } public int ... Read More

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

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 − adds color-related functions to the UIColor class Functionality Prefix Followed by Object CustomView+Animation.swift − adds animation functionality to a custom view class called CustomView JSONEncoder+CustomEncoding.swift − adds custom encoding and decoding functionality to the JSONEncoder class UICollectionViewLayout+Extensions.swift − adds layout-related functions to the UICollectionViewLayout class Descriptive Naming ... Read More

Advertisements