Articles on Trending Technologies

Technical articles with clear explanations and examples

Swift Program to Print even length words

Ankita Saini
Ankita Saini
Updated on 09-May-2023 199 Views

To print even-length words we calculate the length of each word using the count property. Then we check if the length of the word is even or not. If yes, then we will print the word. Otherwise not. Input Str = “Learn Swift language” Output language Here the given string has three words: “Learn", “Swift”, and “language”. But the output is “language” because its length is even that is 8. Algorithm Step 1 − Create a variable to store a string. Step 2 − Split the string into words using the split() function. Step 3 − Now ...

Read More

How to Find Your Exact Location on GPS?

Ankur Choudhury
Ankur Choudhury
Updated on 09-May-2023 609 Views

Ever imagined how essential maps and locations are in our life? Just consider finding a restaurant or looking at a particular store. You open up your phone or tablet, and voila! A street map shows you routes and points of interest along those routes. Are you on holiday in a tourist destination? A map will show you locations, routes, roads, points of interest, and crucial buildings such as restaurants and medical shops. However, these are more challenging to access if you know how to get to your current location. Moreover, in case of an emergency or a critical situation, you ...

Read More

Swift Program to Pass Dictionary as the function argument

Ankita Saini
Ankita Saini
Updated on 09-May-2023 1K+ Views

A Swift dictionary is an unordered collection in which data is stored as key-value pairs. So to pass a dictionary as a function argument simply create a function with an argument of dictionary type and a dictionary, then pass it to the function at the time of function calling. Syntax func functionName(dict:[DataType:DataType]){ // Body } So this is how you can define a function which takes a dictionary as its argument. functionName(dict:DictionayName) This is how you can pass a dictionary as a function argument. Dict.last Here Dict is the name of the dictionary from ...

Read More

Swift Program to merge two integer arrays without using library function

Ankita Saini
Ankita Saini
Updated on 09-May-2023 354 Views

In Swift, we can merge two or more integer arrays without using the library function. So Swift provides an addition assignment(+=) operator to merge two integer arrays. Using this operator we will merge two arrays and assign the result into a new array. Syntax newArray += array Here, newArray is the resultant array and array represents the array which we want to merge. Algorithm Step 1 − Create a function that takes two arrays as an argument and returns a merged array. Step 2 − Inside the function create an empty array to store the resultant array. Step ...

Read More

Swift Program to Merge two Dictionaries

Ankita Saini
Ankita Saini
Updated on 09-May-2023 2K+ Views

To merge the content of two dictionaries Swift provides a pre-defined function named merging(_:uniqueKeysWith:). This function creates a new dictionary by merging the elements of two dictionaries. It also uses a combining closure to check the values for duplicate keys. Syntax func merging(otherDict){comClosure} This function takes two parameters and they are − OtherDict − It is a dictionary to merge. comClosure − It is a closure which takes current and new values for the duplicate keys and then returns the desired value for the output dictionary. It is an optional parameter that means if you don’t want ...

Read More

Swift Program to Insert a string into another string

Ankita Saini
Ankita Saini
Updated on 09-May-2023 1K+ Views

Swift provides a function named insert() to insert a string into another string. The insert(at:) function adds a new character or string in the current string at the specified position. Input String = “Program to learn” New String = “Swift” Output String = Swift Program to learn” Here we insert a new string in the input String at index 1. So we get “Swift Program to learn” in the output. Syntax func insert(newVal, at: idx) Where newVal represents a new string which we want to insert into the given string, and idx is the valid index to ...

Read More

Swift Program to Get key from Dictionary using the value

Ankita Saini
Ankita Saini
Updated on 09-May-2023 3K+ Views

A dictionary is a collection of key-value pairs. Which means keys and values are interrelated with each other. So using a value we can easily get single or multiple keys from the given dictionary. Algorithm Step 1 − Create a dictionary with key-value pairs. Step 2 − Then create a function which will return the key from the dictionary using the value. Step 3 − Inside the function we run a for-in loop which iterates over the key-value pairs of the given dictionary. Step 4 − Now check if the current value is equal to the specified value. If ...

Read More

How to prevent custom views from losing state across screen orientation changes ?

Vaibhav Ahire
Vaibhav Ahire
Updated on 09-May-2023 550 Views

Introduction Many times in android applications we can get to see when the user changes the screen orientation of the device from portrait to landscape. In that case we can get to see that some of the views within the application loses its state. For example when a user enters any data in a text file and then changes the screen orientation from portrait to landscape, in that case the data which is already entered gets cleared up. To prevent this we have to store the state of that view. In this article we will take a look on How ...

Read More

Swift Program to Find the Frequency of Characters in a String

Ankita Saini
Ankita Saini
Updated on 09-May-2023 1K+ Views

In Swift, the frequency of all the characters in a string means how much time a character repeats in the given string. For example, “Swift tutorial”, here “t” repeats 3 times in the given string, “i” repeat 2 times in the given string. So in this article, we are going to find the frequency of all the characters in the string. Algorithm Step 1 − Create a variable to store a string. Step 2 − Create a dictionary to store the character and its count. Step 3 − Run a for loop to iterate over each character in the ...

Read More

Swift Program to delete prefix substring from the given string

Ankita Saini
Ankita Saini
Updated on 09-May-2023 1K+ Views

To delete the prefix substring from the given string first, we check if the given substring is present in the specified string or not using the inbuilt hasPrefix() function. Then find the index of the prefix substring using the inbuilt index() function and finally remove the prefix substring. Input String = “Today is cloudy day” SubString = “Today” Output “is cloudy day” Here, the specified substring is found in the given string, so in the resultant string, we removed the substring from the start of the input string. Algorithm Step 1 − Create a string. Step 2 ...

Read More
Showing 37081–37090 of 61,297 articles
Advertisements