Sunday, March 26, 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 SwiftUI for iOS 15 – Hacking with Swift

learningcode_x1mckf by learningcode_x1mckf
September 13, 2022
in Swift
0
How to use inner shadows to simulate depth with SwiftUI and Core Motion – Hacking with Swift
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter



You might also like

Introducing – AI Utils for macOS

Encoding and decoding data using the Hummingbird framework

Hummingbird routing and requests – The.Swift.Dev.

Expectations have been at all times going to be excessive for SwiftUI this 12 months, however the staff didn’t disappoint – they’ve shipped a large assortment of enhancements and options, together with a brand new AsyncImage view for loading distant photos, swipe actions for listing rows, pull to refresh, plus shorter, less complicated APIs for widespread makes use of. Alongside large enhancements to Swift itself (see What’s new in Swift 5.5 for extra on that), that is one other vital leap ahead for SwiftUI and I’m actually eager to dive in.

Please needless to say these modifications are very new – I am pushing it as exhausting as I can, experimenting, refining, sharing, and studying all on the similar time. In case you have any suggestions, please tweet me @twostraws.

You may watch the video beneath, or scroll down for hyperlinks to articles.

Sponsor Hacking with Swift and reach the world’s largest Swift community!

The large stuff

Extra welcome enhancements

An vital animation deprecation

The one-parameter type of the animation() modifier has now been formally deprecated, principally as a result of it brought on all kinds of surprising behaviors. To see the issue your self, strive code like this:

struct ContentView: View 
    @State personal var scaledUp = true

    var physique: some View 
        VStack 
            Textual content("Whats up, world!")
                .scaleEffect(scaledUp ? 2 : 1)
                .animation(.linear(length: 2))
                .onTapGesture  scaledUp.toggle() 
        
    

That appears easy sufficient: animation the textual content getting bigger or smaller when it’s tapped. Nevertheless, we connected the animation to every thing for the label, which implies even one thing like rotating the display would make the textual content label animate from its outdated place to its new place.

The answer right here is to make use of animation(_:worth:) to connect your animation to a selected worth altering, like this:

struct ContentView: View 
    @State personal var scaledUp = true

    var physique: some View 
        VStack 
            Textual content("Whats up, world!")
                .scaleEffect(scaledUp ? 2 : 1)
                .animation(.linear(length: 2), worth: scaledUp)
                .onTapGesture  scaledUp.toggle() 
        
    

Toggle buttons

iOS 15 offers a center floor between Button and Toggle, which is a Toggle that seems to be like a button however flips its foreground and background colours in its on state. That is enabled utilizing the .button toggle fashion, as proven within the following code:

struct ContentView: View 
    @State personal var isOn = false

    var physique: some View 
        Toggle("Filter", isOn: $isOn)
            .toggleStyle(.button)
            .tint(.mint)
    

Automated picture choice for TabView

In iOS 15 SwiftUI now routinely selects the proper variant of an SF Symbols icon when used inside a TabView.

Based on the iOS human interface pointers icons should be stuffed when used inside a TabView, however in accordance with the macOS human interface pointers they need to be stroked. To make this work nicely on each platforms, now you can specify the straightforward, unfilled type of the picture and have SwiftUI use the proper variant as acceptable for the platform.

So, on iOS this may present the stuffed types of every of our icons:

TabView 
    Textual content("View 1")
        .tabItem 
            Label("House", systemImage: "home")
        

    Textual content("View 2")
        .tabItem 
            Label("Account", systemImage: "particular person")
        

    Textual content("View 3")
        .tabItem 
            Label("Group", systemImage: "theatermasks")
        

Main actions for menus

In iOS 15 menus may have a main motion connected, which is triggered when the menu’s button is tapped moderately than held down. So, you press and launch to set off the first motion, or maintain all the way down to get the complete menu of choices.

We may create a menu that helps each easy faucets in addition to a full set of choices:

struct ContentView: View 
    var physique: some View 
        Menu("Choices") 
            Button("Order Now", motion: placeOrder)
            Button("Regulate Order", motion: adjustOrder)
            Button("Cancel", motion: cancelOrder)
         primaryAction: 
            justDoIt()
        
    

    func justDoIt() 
        print("Button was tapped")
    

    func placeOrder()  
    func adjustOrder()  
    func cancelOrder()  

And there’s extra…

There’s a more recent, less complicated technique to dismiss views programmatically. Moderately than utilizing the presentationMode setting key then calling presentationMode.wrappedValue.dismiss(), it is best to as a substitute use the brand new .dismiss) setting key:

@Atmosphere(.dismiss) var dismiss

That makes use of Swift’s callAsFunction(), so with that in place now you can make a sheet dismiss itself by calling dismiss().

There is a new format parameter when creating Textual content views, permitting you to format the worth as an inventory, as a share, as a measurement, and extra. You may examine this modification right here: How to format text inside text views

iOS 15 helps you to connect a task to your button to assist SwiftUI know what sort of styling needs to be connected to the button. For instance, if we had a Delete button we would mark it with the .damaging function so SwiftUI can spotlight it in pink when it is sensible:

Button("Delete", function: .damaging) 
    print("Carry out delete")

Plus, there are stacks of enhancements which have come about due to enhancements in Swift itself. You will discover out extra in my article What’s New in Swift 5.5, however right here’s the abridged model.

First, types now use a lot less complicated names: SidebarListStyle() turns into simply .sidebar, and RoundedBorderTextFieldStyle() turns into simply .roundedBorder.

Second, now you can use #if for postfix member expressions, like this:

Textual content("Welcome")
#if os(iOS)
    .font(.largeTitle)
#else
    .font(.headline)
#endif

And third, Swift 5.5 is ready to implicitly convert between CGFloat and Double in most locations the place it’s wanted, which implies you may just about take away CGFloat out of your SwiftUI code.

One other nice 12 months!

Final 12 months was large for SwiftUI, however this 12 months the framework is de facto maturing – we’re seeing outdated UIKit controls corresponding to UIVisualEffectView and UISearchController being dramatically rethought for a SwiftUI world, and the outcomes are fairly darn unbelievable.

Because of the SwiftUI staff for doing such an unbelievable job this 12 months, and to Apple’s developer publications staff for working so exhausting to create implausible documentation we will all be taught from!

Sponsor Hacking with Swift and reach the world’s largest Swift community!



Source link

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

Introducing – AI Utils for macOS

by learningcode_x1mckf
March 24, 2023
0
Introducing – AI Utils for macOS

⚠️ REQUIRES a FREE OpenAI API key. You will get one utilizing this hyperlink. ⚠️ Improve your productiveness with our AI powered utility application. - accessible...

Read more

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
Next Post
Conditional Logic & Control Flow – Real Python

Conditional Logic & Control Flow – Real Python

Leave a Reply Cancel reply

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

Related News

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

JavaScript security best practices for securing your applications – Security Boulevard

February 24, 2023
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How to Fix the Discord Fatal Javascript Error in Windows 10 & 11 – MUO – MakeUseOf

February 10, 2023
Java Developer at Sabenza IT

Senior C++ developer at Hire Resolve – IT-Online

September 24, 2022

Browse by Category

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

RECENT POSTS

  • YS Jagan launches Ragi Java in Jagananna Gorumudda, says focused on intellectual development of students – The Hans India
  • Disadvantages of Java – TheServerSide.com
  • Advantages of Java – TheServerSide.com

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?