Our website

JAX.Network blockchain is secure, decentralized and scalable possessing all three aspects to solve the Blockchain Scalability Trilemma. The development team of expert engineers and scientists are…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Replace or Remove a String in your Array

Working on a project today, I ran into a solution that would be good to share with IOS Developers. That is using a swift tool .firstIndex(of: String) to find or replace an indexed string in your array. In my case this was used for error handling!

I have an array setup called var testSlice: [String] = [] which is the final form of var items: [String] = []. The items array is holding strings that represent profilePic id’s that get used in a method later on in the class file.

Empty strings "" were in the array as placeholder values, that needed removed before the array passed its data to a UICollectionView .

Here is my solution using .firstIndex(of: String) :

In the first line we are checking for items that contain an empty string at their index and storing it in a variable. The index found then gets passed to the .remove function as an int .. removing it from our testSlice array.

After thats done the collectionView data gets reloaded. Attached is a picture of the UI as an example to show whats possible. I hope this helped, and served its purpose as an easy solution!

Add a comment

Related posts:

Finding Your Publication Path

A familiar question came up in a writing workshop I led last week. A participant wanted to know how to publish the many stories he had accumulated during his unusual life. It’s a common and important…

Activation Functions in Neural Networks

A neural network technique is very similar to how our brain understands. The brain takes stimuli as inputs, processes them, and outputs accordingly. A neural network is connected with many neurons as…

5 Ways You Can Stay Fit While Traveling

With more things starting to open up, you may be itching to take a trip. Whether it’s now, or in the future, a vacation is an easy way to leave fitness behind. Vacations are great, but there can be a…