logo
logo
AI Products 

What's New in SwiftUI 3.0

avatar
Expert App Devs
What's New in SwiftUI 3.0

swiftui 3

SwiftUI 3.0 available on iOS 15, iPadOS 15, macOS 12, and watchOS 12.

Markdown Support and New AttributedString API

  • In swiftUI 3.0 we can modified string using markdown and attributedString
  •  
  • We can add a string with markdown syntax as below:-

Text("**Connect** on [Twitter](url_here)!")

Connect on Twitter

  • If customize a range of character in string then use attributed string as per below:-

do {

let thankYouString = try AttributedString(
markdown:"**Welcome** to
[website](https://example.com)")

} catch {

print("Couldn't parse: \(error)")

}

New Button Style

  • Cancel
  •  
  • Destructive
  •  
  • None
  •  
  • Some (Publisher)
  •  
  • You can apple Bordered button style, Borderless button style, plain button style and default button style by using the button style modifier

    New Button Style

AsyncImage for load image from url

  • SwiftUI Abstract all long process by using async image 

AsyncImage(url: URL(string: <url_here>)!)

  • You can also add a placeholder while fetching image

    AsyncImage

Better keyboard management

  • In SwiftUI 3.0 new property wrapper (@FocusState) to manage the current active text field by programmatically

Here is an example:-  

FocusState

  • Submit label view modifier use for set keyboard return key with different types of options

SwiftUI list Searchable

  • Apple brings a searchable modifier to search from the list 
  •  
  • You need to wrap it inside a navigation view

Here is an example of a searchable list:-
struct Colors:

Identifiable{

var id = UUID()
var name: String
}

struct SearchingLists: View {

@State var searchText: String = ""
@State private var color: [Color] = [Color(name: "Blue"),Color(name: "Red"),Color(name: "Green")]

       var body: some View {

NavigationView {
List($color) { $color in
Text(color.name)
}

.searchable("Search color", text: $searchText, placement: .automatic){
Text("re").searchCompletion("red")
Text("b")
}

.navigationTitle("Colors List")
}

}

}

We can use onSubmit modifier to display search result real-time as shown below:- 

searchable list

SwiftUI list Pull to refresh

  • With use for refreshable modifier, we can integrate pull to refresh function as per below example:-
    SwiftUI list Pull

SwiftUI List Swipe Action

  • We can swipe a row of the list and implement the button using swipeActions modifier.
  •  
  • By default swipe action work from the trailing side, we can also implement from leading by using one line code.

.swipeActions(edge: .leading)

  • We can also implement both side swipe actions using chaining multiple identifier.

    Swipe Action

Brand New SwiftUI Material Struct

  • This material struct use for blend to foreground element with the background.
  •  
  • By adding translucency and vibrancy to views, we can use in following ways :-

.background(.regularMaterial)
.background(.thinMaterial)
.background(.ultraThinMaterial)
.background(.thickMaterial)
.background(.ultraThicknMaterial)

Material Struct

collect
0
avatar
Expert App Devs
guide
Zupyak is the world’s largest content marketing community, with over 400 000 members and 3 million articles. Explore and get your content discovered.
Read more