Monday, July 4, 2022
Techiexpert.com
No Result
View All Result
  • Login
  • Register
Exclusive Videos
  • Tech news
  • Startup news
  • Artificial Intelligence
  • IOT
  • Big Data
  • Cloud
  • Data Analytics
  • Machine Learning
  • Blockchain
  • Social Media
  • Tech news
  • Startup news
  • Artificial Intelligence
  • IOT
  • Big Data
  • Cloud
  • Data Analytics
  • Machine Learning
  • Blockchain
  • Social Media
No Result
View All Result
TechiExpert
No Result
View All Result

5 Features of The New Apple’s Swift 5 Language

Harry Miller by Harry Miller
July 12, 2019
in Uncategorized
Reading Time: 5 mins read
5 Features of The New Apple's Swift 5 Language 1
11
SHARES
150
VIEWS
Share on FacebookShare on Twitter

Let’s look at the new features of Swift 5 Language used to develop IOS apps, Coders are the unsung heroes of this century. We rarely give coders the credit they deserve. Without them, we would not be able to enjoy any of the technology we use in our daily lives.

Things like Spectrum internet ultra would not even exist. This is not as much an opinion as it is a fact. Why? Because, every bit of technology, including the device you are reading this blog on, uses the code.

There are more than 700 programming languages in use today. Some are more advanced and some are limited for use with certain devices, like Swift. Swift is a programming language designed by Apple. macOS, iOS, watchOS, all use the Swift programming language.

Earlier this year, Apple released a welcomed update for its programming language, Swift 5.0. This major update included some new features based on user feedback.

What’s New in the Latest Swift 5.0 Upgrade?

This was the most awaited upgrade since the Swift 4.2 version. The 5.0 version also addressed the biggest issue of ABI stability. Application Binary Interface (ABI) is the interface that links two binary program modules. Simply put, It defines how computational routines are accessed in machine code. However, the new version also offers many other features:

  • Dictionary Values with compactMapValues()
  • Integer Multiples Check
  • Flattening Nested Options
  • Raw Strings

#1. Dictionary Values with compactMapValues()

Using SE-0218 You can add a new compactMapValues() method to dictionaries, bringing together the compactMap() functionality from arrays (“transform my values, unwrap the results, then discard anything that’s nil”) with the mapValues() method from dictionaries (“leave my keys intact but transform my values”).

As an example, check this dictionary of people in one particular race. It includes the names and finishing times in seconds. Marked as “DNF” was one who did not finish:

let times = [
"Mark": "38",
"John": "42",
"Curtis": "35"
"Cole": "DNF"
]

Now we can use compactMapValues() to create a new dictionary. In this one, the names and times are shown as an integer, with the one DNF person removed:

let finishers1 = times.compactMapValues { Int($0) }

Alternatively, you can also pass the Int initializer directly to compactMapValues(), like this:

let finishers2 = times.compactMapValues(Int.init)

Without any transformation, you can also use compactMapValues() to unwrap optionals and discard nil values, like this:

let people = [
"Jack": 38,
"Caroline": 8,
"Sasha": 5,
"Amber": nil
]

let knownAges = people.compactMapValues { $0 }

#2. Integer Multiples Check

Using SE-0225 you can add an isMultiple(of:) method to integers. This allows you to check whether one number is a multiple of another in a much clearer way than using the division remainder operation, %.

For example:

let rowNumber = 4
 if rowNumber.isMultiple(of: 2) {
 print("Even")
 } else {
 print("Odd")
 }

Of course, you could write check using if rowNumber % 2 == 0 but that is less clear – having isMultiple(of:) as a method means it can be listed in code completion options in Xcode. This helps with discoverability.

#3. Flattening Nested Optionals

Using SE-0230 you can modify the way try? works. This way nested optionals can be flattened to become regular optionals. This allows it to function similar to optional chaining and conditional typecasts.

Here’s a practical example that demonstrates the change:

struct User {
var id: Int
init?(id: Int) {
if id < 1 {
return nil
}
self.id = id
}
func getMessages() throws -> String {
// complicated code here
return "No messages"
}
}

let user = User(id: 1)

let messages = try? user?.getMessages()

#4. Raw Strings

Using SE-0200 you can now formulate raw strings on Swift. Instead of using quotation marks and backslashes as string terminators or escapes characters, they are construed as the symbols they are. Use cases become much easier with this method. But what gets the most gains is regular expressions.

Try placing one or more # symbols before your strings, to use raw strings. As illustrated below:

let rain = #”The “rain” in “Spain” falls mainly on the Spaniards.”#

The # symbols that are positioned at the beginning and end of the string sequence are very important. They become part of the string delimiter. Swift 5.0 can understand that the quotation symbols around “Spain” and “rain” need to be considered as simple quotation symbols, instead of string terminators.

You can also use backslashes in raw strings, like this:

let keypaths = #”Swift keypaths such as Person.name hold uninvoked references to properties.”#

This denotes backslashes as actual characters, instead of denoting it as escape characters. That makes the string interpolation work in a completely different way:

let answer = 42

let dontpanic = #”The answer to life, the universe, and everything is #(answer).”#

Note how #(answer) is used for string interpolation. This way, a normal (answer) can be denoted simply as string characters. When you are aiming for string interpolation in a raw string set, the additional # need to be included.

Conclusion

These are some of the new features of the Swift 5.0 programing language. You can find out about many more once you start using it. This is one of the best things about upgrades to languages. This excitement of finding the new features is not comparable to much else.

If it could be compared to anything, it would be like finding out this question most probably: Is 100 Mbps Fast? In addition to all the new features, there is even more good news about the Swift programming language. Apple has already announced that there is a Swift 5.1 version rolling out. The new version will have improvements including module stability.

Tags: AppleiOSMobile Tech
Share4Tweet3Share1Pin1

Related Posts

Backlinks
Marketing Trends

Doing Cleanup: 5 Types of Links You Should Disavow

Telemedicine Business
Tech news

Telemedicine or e-medicine: What is it?

Hyperlocal marketplace Urvann raises Rs. 3 Cr in Seed Round led by IPV
Startup news

Hyperlocal marketplace Urvann raises Rs. 3 Cr in Seed Round led by IPV

Does domain extension impact SEO standards
Blogging

Does domain extensions impact SEO standards

Ways Data Analysis has changed customer reward programs
Tech news

Ways Data Analysis has changed customer reward programs

Most Read

  • How to Track Someone’s iPhone by Phone Number?

    How to Track Someone’s iPhone by Phone Number?

    503 shares
    Share 201 Tweet 126
  • Top 5 car automation trends to know

    274 shares
    Share 110 Tweet 69
  • Is Parody Coin investment a Good Investment?

    101 shares
    Share 40 Tweet 25
  • What is windows modules installer ? How to Enable/Disable

    1246 shares
    Share 498 Tweet 312
  • Tips to Reduce Your Website Hosting Costs

    882 shares
    Share 352 Tweet 220
  • How to Track Activities an Instagram account?

    88 shares
    Share 35 Tweet 22

Recent Stories

Here’s why Deep Learning might not be enough for celebrity face recognition

Digital Learning face recognition
Share5Tweet3Share1Pin3

How Enterprise Blockchain can enable Privacy Preservation

How Enterprise Blockchain can enable Privacy Preservation
Share5Tweet3Share1Pin1

How to flip NFT’s

How to flip NFTs
Share5Tweet3Share1Pin1

Staying Safe When Trading on a Trading App

VPS Helps Forex Trading
Share5Tweet3Share1Pin1
  • Terms of use
  • Privacy Policy
  • About Us
  • Contact us
  • Write For Us
  • Cookie Policy

© 2022 All Rights Reserved

No Result
View All Result
  • Tech news
  • Startup news
  • Artificial Intelligence
  • IOT
  • Big Data
  • Cloud
  • Data Analytics
  • Machine Learning
  • Blockchain
  • Social Media

© 2022 All Rights Reserved

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms below to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Cookie Law Notice
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT