Friday, March 24, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home Swift

What’s new in Swift 5.3?

learningcode_x1mckf by learningcode_x1mckf
September 22, 2022
in Swift
0
What’s new in Swift 5.3?
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


2020/05/14

Swift 5.3 goes to be an thrilling new launch. This put up is a showcase of the newest Swift programming language options.

Swift

The Swift 5.3 release process began in late March, there are many new options which are already carried out on the 5.3 department. In case you are curious what are these you’ll be able to attempt it out by putting in the newest snapshot utilizing swiftenv for instance, you’ll be able to seize them from swift.org.



Bundle Supervisor updates

Swift Bundle instruments model 5.3 will function some actually nice additions.


Sources

With the implementation of SE-0271 the Swift Bundle Supervisor can lastly bundle useful resource recordsdata alongside code. I consider that this was fairly a well-liked request, since there are some libraries that embed asset recordsdata, they weren’t ready so as to add SPM help, till now.


Localized sources

SE-0278 extends the useful resource help, with this implementation you’ll be able to declare localized sources to your Swift packages. The outline explains properly the proposed construction, you need to have a look in case you are concerned with delivery localized recordsdata along with your bundle.


Binary dependencies

The opposite great point is that SPM will lastly be capable to use binary dependencies. SE-0272 provides this functionality so individuals who wish to ship closed supply code can now benefit from this function. It will make it attainable to have a binaryTarget dependency at a given path or location and you need to use the binary as a product in a library or executable.


Conditional Goal Dependencies

SE-0273 provides us a pleasant little addition so we will use dependencies primarily based on given platforms. Which means that you need to use a product for a goal whenever you construct for a selected platform.


These options are nice additions to the SPM, hopefully Xcode will profit from this stuff as properly, and we are going to see some nice new enhancements within the upcoming model of the IDE too.



Language options

There are various new attention-grabbing proposals that acquired into the 5.3 model.


A number of Trailing Closures

SE-0279 is without doubt one of the most debated new proposal. Once I first noticed it I used to be undecided in regards to the want of it, why would somebody put a lot effort to get rid of a number of brackets? 🤔

import UIKit

class ViewController: UIViewController 

    override func viewDidLoad() 
        tremendous.viewDidLoad()

        
        UIView.animate(withDuration: 0.3, animations: 
          self.view.alpha = 0
        , completion:  _ in
          self.view.removeFromSuperview()
        )
        
        UIView.animate(withDuration: 0.3, animations: 
          self.view.alpha = 0
        )  _ in
          self.view.removeFromSuperview()
        

        
        UIView.animate(withDuration: 0.3) 
          self.view.alpha = 0
        
        
        UIView.animate(withDuration: 0.3) 
            self.view.alpha = 0
         completion:  _ in
            self.view.removeFromSuperview()
        
    

As you’ll be able to see that is principally a syntactic sugar, however I satisfied myself that it’s good to have.


Synthesized Comparable conformance for enum varieties

Enum varieties do not need to explicitly implement the Comparable protocol because of SE-0266.

enum Membership: Comparable 
    case premium(Int)
    case most well-liked
    case normal

([.preferred, .premium(1), .general, .premium(0)] as [Membership]).sorted()

The Comparable protocol is routinely synthesized, similar to the Equatable and Hashable conformances for eligible varieties. After all you’ll be able to present your individual implementation if wanted.


Enum instances as protocol witnesses

Swift enums are loopy highly effective constructing blocks and now they simply acquired higher. 💪


protocol DecodingError 
  static var fileCorrupted: Self  get 
  static func keyNotFound(_ key: String) -> Self


enum JSONDecodingError: DecodingError 
  case fileCorrupted
  case keyNotFound(_ key: String)

The principle objective of SE-0280 to elevate an current restriction, this manner enum instances may be protocol witnesses if they supply the identical case names and arguments because the protocol requires.


Kind-Primarily based Program Entry Factors

SE-0281 provides us a brand new @major attribute that you need to use to outline entry factors to your apps. This can be a welcome addition, you do not have to put in writing the MyApp.major() methodology anymore, however merely mark the MyApp object with the primary attribute as a substitute.

@major
class AppDelegate: UIResponder, UIApplicationDelegate 

    static func major() 
        print("App will launch & exit instantly.")
    

The UIApplicationMain and NSApplicationMain attributes can be deprecated in favor of @major, I might guess that is coming with the following main launch…


Multi-Sample Catch Clauses

SE-0276 is one other syntactic sugar, it is actually helpful to catch a number of instances without delay.

do 
    attempt performTask()

catch TaskError.someRecoverableError 
    get well()

catch TaskError.someFailure(let msg), TaskError.anotherFailure(let msg) 
    showMessage(msg)

This eliminates the necessity of utilizing a change case within the catch block. ✅


Float16

Nothing a lot to say right here, SE-0277 provides Float16 to the usual library.

let f16: Float16 = 3.14

Generic math functions are additionally coming quickly…


Self adjustments


SE-0269 aka. Improve availability of implicit self in @escaping closures when reference cycles are unlikely to happen is a pleasant addition for individuals who don’t love to put in writing self. 🧐


execute 
    let foo = self.doFirstThing()
    performWork(with: self.bar)
    self.doSecondThing(with: foo)
    self.cleanup()



execute  [self] in
    let foo = doFirstThing()
    performWork(with: bar)
    doSecondThing(with: foo)
    cleanup()

It will permit us to put in writing self within the seize listing solely and omit it afterward contained in the block.


Refine didSet Semantics

SE-0268 is an below the hood enchancment to make didSet habits higher & extra dependable. 😇

class Foo 
    var bar = 0 
        didSet  print("didSet known as") 
    

    var baz = 0 
        didSet  print(oldValue) 
    


let foo = Foo()

foo.bar = 1

foo.baz = 2

In a nutshell beforehand the getter of a property was at all times known as, however any longer it will be solely invoked if we use to the oldValue parameter in our didSet block.


Add Assortment Operations on Noncontiguous Components

SE-0270 provides a RangeSet sort for representing a number of, noncontiguous ranges, in addition to quite a lot of assortment operations for creating and dealing with vary units.

var numbers = Array(1...15)


let indicesOfEvens = numbers.subranges(the place:  $0.isMultiple(of: 2) )


let sumOfEvens = numbers[indicesOfEvens].cut back(0, +)

let rangeOfEvens = numbers.moveSubranges(indicesOfEvens, to: numbers.startIndex)

This proposal additionally extends the Assortment sort with some API strategies utilizing the RangeSet sort, you need to have a look in case you are working loads with ranges. 🤓


The place clauses on contextually generic declarations

With SE-0267 you can implement capabilities and put a the place constraint on them in case you are solely referencing generic parameters. Think about the next snippet:

protocol P 
    func foo()


extension P 
    func foo() the place Self: Equatable 
        print("lol")
    

This may not compile on older variations, however it’ll work like magic after Swift 5.3.


Add a String Initializer with Entry to Uninitialized Storage

SE-0263 provides a brand new String initializer that means that you can work with an uninitialized buffer.

let myCocoaString = NSString("The fast brown fox jumps over the lazy canine") as CFString
var myString = String(unsafeUninitializedCapacity: CFStringGetMaximumSizeForEncoding(myCocoaString, ...))  buffer in
    var initializedCount = 0
    CFStringGetBytes(
        myCocoaString,
        buffer,
        ...,
        &initializedCount
    )
    return initializedCount


By utilizing this new init methodology you do not have to fiddle with unsafe pointers anymore.



Future evolution of Swift

Presently there are 6 extra accepted proposals on the Swift evolution dasboard and one is below assessment. Swift 5.3 goes to comprise some wonderful new options that had been lengthy awaited by the group. I am actually glad that the language is evolving in the suitable path. 👍




Source link

You might also like

Encoding and decoding data using the Hummingbird framework

Hummingbird routing and requests – The.Swift.Dev.

Building a Scrollable Custom Tab Bar in SwiftUI

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

Encoding and decoding data using the Hummingbird framework

by learningcode_x1mckf
March 22, 2023
0
Encoding and decoding data using the Hummingbird framework

HTTP is all about sending and receiving information over the community. Initially it was solely utilized to switch HTML paperwork, however these days we use HTTP to switch...

Read more

Hummingbird routing and requests – The.Swift.Dev.

by learningcode_x1mckf
March 17, 2023
0
Hummingbird routing and requests – The.Swift.Dev.

Routing on the server facet means the server goes to ship a response primarily based on the URL path that the consumer referred to as when firing up...

Read more

Building a Scrollable Custom Tab Bar in SwiftUI

by learningcode_x1mckf
March 10, 2023
0
Building a Scrollable Custom Tab Bar in SwiftUI

Whether or not you’re making a social media app or a productiveness device, the tab bar interface can improve the consumer expertise by making it extra intuitive and...

Read more

Beginner’s guide to server-side Swift using the Hummingbird framework

by learningcode_x1mckf
March 8, 2023
0
Beginner’s guide to server-side Swift using the Hummingbird framework

Swift on the Server in 2023 Three years in the past I began to focus on Vapor, the preferred web-framework written in Swift, which served me very...

Read more

What’s new in Swift 5.8 – Hacking with Swift

by learningcode_x1mckf
March 8, 2023
0
What’s new in Swift 5.8 – Hacking with Swift

Though many main Swift modifications are at present percolating by way of Swift Evolution, Swift 5.8 itself is extra of a clear up launch: there are additions, sure,...

Read more
Next Post
Better Date and Time Management in JavaScript

Better Date and Time Management in JavaScript

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Working With Linear Systems in Python With scipy.linalg – Real Python

Working With Linear Systems in Python With scipy.linalg – Real Python

January 18, 2023
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Java or Php: The eternal struggle of my professional career – Medium

February 8, 2023
Swift delegate design pattern – The.Swift.Dev.

Swift delegate design pattern – The.Swift.Dev.

October 5, 2022

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • Java Developer Survey Reveals Increased Need for Java … – PR Newswire
  • What You Should Definitely Pay Attention to When Hiring Java Developers – Modern Diplomacy
  • Java Web Frameworks Software Market Research Report 2023 … – Los Alamos Monitor

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?