MobileEntityLogo.png

Hi.

Welcome to the best online resource for IOS & Android tutorials.

This should be part of the Foundation library in Swift

This should be part of the Foundation library in Swift

In some languages we can compare value of different types by using the === When doing this you can compare 1 === “1“ and return true. I may submit a proposal to contribute to the Swift Evolution Process. My current fix is very hacky, however I know that their is a low level way of achieving this in Swift. Comparing Integers, Doubles, Floats, and any numerical type against a string shouldn’t require more then one line of code. It is something simple, yet powerful. If you are retrieving a number in String format from a database you shouldn’t have to convert to string in order to compare. You should have the === at your fingertips whenever you need it. Here is some code examples of what I am talking about.

Code snippet

As you can see we are comparing numbers where one side is a normal number, and the other side is a number inside of a String. This is something that I find useful. Now This can be done in one function, by using Equatable, however I couldn’t get it to work, so I found a very hacky solution. See code bellow.

Screen Shot 2020-05-08 at 2.51.00 PM.png

This is a quick and dirty solution, however the ideal way would be to use Equatable. If we where to use equatable we could also do some really cool stuff with Classes, and Object like so.

Screen Shot 2020-05-08 at 2.52.58 PM.png

The solution would be that A and B with different names should return false, and when both the have same name equation should return true, however anything we put returns false because Swift doesnt have this functionality. I hope to submit a Swift SEO soon, however this would be my first contribution to the language. The code I will be submitting will be using Equatable, which I couldn’t get it to work for this tutorial. However I know it works after looking at some Equatable examples. Until next time Happy coding.

How to make Strings easier to Debug in Swift

How to make Strings easier to Debug in Swift

How to bring Lottie to SwiftUI

How to bring Lottie to SwiftUI

0