9.8 C
Canberra
Friday, September 20, 2024

WWDC 2024 Recap | Kodeco


WWDC 2024 has come and gone, which appears to occur faster and faster annually, and in its wake are lots of movies to take a look at. There have been so many movies this yr, Apple began releasing them Monday night time after the Platform State of the Union, so that you knew it was going to be a packed week. It might be unattainable to cowl all the brand new materials in a single article. Nonetheless, between the Keynote, the Platform State of the Union, and a few choose movies, listed below are some belongings you positively want to take a look at. These are in no specific order, however all are must-watches in the event you’re an Apple developer.

Swift

Swift 6 is the massive change this yr, though you possibly can fortunately undertake the brand new protected data-race security conformance at your individual tempo, module by module, because of compiler’s Swift 6 language mode choices. Along with utilizing Swift on embedded gadgets, improved C++ interoperability, and non-copyable varieties, two actually cool objects stood out.

Absolutely Static Linux SDK for Swift

Now you can cross-compile your apps for Swift on Linux and embrace the Swift libraries as a totally static element of your app. This implies the vacation spot doesn’t must have Swift put in. This may be nice for deploying issues like net service apps over to a Linux system.

Typed Throws

Now you can used typed throws to get higher suggestions on precisely what error is caught. For instance:

enum MyError: Error {
    misTyped, whatWasIThinking
}

func foo(string: String) throws(MyError) -> String {
    //.....
    throw MyError.misTyped(string)
}

do {
    let response = attempt foo(string: "Howdy world!")
} catch {
    //the error right here is of sort "MyError" as a substitute of simply "Error"
}

For extra on Swift this yr, remember to take a look at What’s new in Swift, and for extra on migrating your mission to Swift 6, take a look at Migrate your app to Swift 6

SwiftUI

SwiftUI bought a good variety of updates this yr, as common. Listed below are among the issues that stood out.

View Is now on the @MainActor

You now not must mark your views with @MainActor as a result of the View protocol now has that ornament. That’s one much less line of code to jot down!

The Magic Floating Tab Bar (or Is it a Sidebar?)

One thing that’s already getting a blended response is the brand new tab view model:

struct TabBarExample: View {
    var physique: some View {
        TabView {
            Textual content("Tab 1")
                .tabItem {
                        VStack {
                        Picture(systemName: "1.circle")
                        Textual content("Tab 1")
                    }
                }
            Textual content("Tab 2")
                .tabItem {
                        VStack {
                        Picture(systemName: "2.circle")
                        Textual content("Tab 2")
                    }
                }
            Textual content("Tab 3")
                .tabItem {
                        VStack {
                        Picture(systemName: "3.circle")
                        Textual content("Tab 3")
                    }
                }
        }
        .tabViewStyle(.sidebarAdaptable)
    }
}

This may end up in one in every of two pictures, relying on whether or not you desire a floating tab bar on the prime (suppose visionOS) or a standard sidebar (suppose NavigationSplitView):

Floating tab bar at top

Traditional sidebar

I haven’t had an opportunity to play rather a lot with this one, however as with all paradigm-breaking issues, there’s often a little bit of disagreement locally about it. We’ll see how this one shakes out!

New Modifiers for Presentation and Zooming

For views represented in a sheet, a brand new modifier helps you to specify web page, type, or customized sizing:

    .presentationSizing(.type)

And to get a pleasant zoom in animation when bringing views to the foreground, a brand new pair of modifiers may help you:

.navigationTransition(.zoom(
                    sourceID: merchandise.id, in: namespace))
                    
///....

.matchedTransitionSource(id: merchandise.id, in: namespace)
}


For extra on SwiftUI this yr, remember to take a look at What’s new in SwiftUI.

SwiftData

SwiftData didn’t have an enormous replace this yr like some had been hoping, nevertheless it did get some very essential updates to assist with efficiency and queries. This yr, Apple added the power to specify distinctive constraints with the #Distinctive macro and generally listed fields with Index. With just some strains of code, you possibly can add these options to an present @Mannequin:

import SwiftData
import Basis

@Mannequin
class KodecoArticle {
    
    #Distinctive([.name, .dateWritten, .author])
    #Index([.name], [.dateWritten], [.author], [.name, .dateWritten, .author])
    
    var title: String = ""
    var creator: String = ""
    var content material: String = ""
    var dateWritten: Date?
    var dateUpdated: Date?
    
    init(title: String, creator: String, content material: String, dateWritten: Date? = nil, dateUpdated: Date? = nil) {
        self.title = title
        self.creator = creator
        self.content material = content material
        self.dateWritten = dateWritten
        self.dateUpdated = dateUpdated
    }
    
}

The #Distinctive line states that entries are distinctive on that mixture of properties, and the #Index line lists which properties, or mixture of properties, are added as further metadata to the mannequin so it will probably carry out sooner queries.

Apple additionally unveiled different new options for SwiftData, equivalent to utilizing your individual customized knowledge retailer! For extra, take a look at What’s New in SwiftData.

Frameworks That Are In all places

There have been two sturdy examples of frameworks that had been gaining parity and energy over many if not all the platforms Apple gives. There’s rather a lot to cowl right here, so right here they’re together with hyperlinks to the WWDC movies.

App Intents

Over the previous few years, App Intents has turn into a significant participant in the case of surfacing your app’s options; whether or not it’s to shortcuts, Siri, or widgets.

This yr, App Intents will get one other improve as a result of it’s the mechanism to hook your app into Apple Intelligence. For extra, remember to take a look at What’s new in App Intents, Carry your app’s core options to customers with App Intents, and Carry your app to Siri.

RealityKit

Through the years, RealityKit hasn’t been very uniform throughout the platforms, making it exhausting to deploy the identical app to totally different Apple {hardware}. That modifications this yr, as RealityKit has lots of new cross-platform APIs throughout all the assorted platforms — visionOS, macOS, iOS, and iPadOS. For extra, take a look at Uncover RealityKit APIs for iOS, macOS, and visionOS.

Swift Testing

Along with transferring the open supply Swift elements to the swiftlang group at GitHub, Apple has formally included Swift Testing in that household of libraries. Swift Testing is a brand new method of testing in Swift (however complementary to XCTest), introducing extra “Swifty” syntax to your check code. Right here’s a fast instance:

import Testing

struct WWDCTests {

    @Check func testExample() async throws {
        let worth = 2
        #anticipate(worth + worth == 3)
        
        let value2: Int? = nil
        _ = attempt #require(value2)
    }

}

After importing the Testing framework, you enhance your assessments with the @Check attribute. This implies you now not want to call your check strategies so they begin with “check”. I’ve added a couple of issues to check. The primary makes use of the #anticipate macro, which replaces the household of XCTAssert calls and checks to see whether or not the situation inside is true. The following code block checks that value2 just isn’t nil earlier than continuing through the use of the #require macro. See what Xcode says when the check button is clicked:

Test results

In the proper gutter, you see indications that the expectations failed. For the primary one, in the event you hover over the error, a “Present” button seems you can click on to get extra particulars, as proven within the screenshot. This allows you to dive into why precisely the examined code failed.

This appears to be rather a lot cleaner than XCTest (though you need to use each in your assessments!), and I can’t wait to start out utilizing it. For extra about Swift Testing, take a look at Meet Swift Testing.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles