From iOS 15.0+, apple has introduced AsyncImage.

AsynceImage: A view that asynchronously loads and displays an image.

This view uses the shared URLSession instance to load an image from the specified URL, and then display it. For example, you can display an icon that’s stored on a server:

AsyncImage(url: URL(string: “https://example.com/image.png")) .frame(width: 200, height: 200)

You can specify a custom placeholder using init(url:scale:content:placeholder:).

AsyncImage(url: URL(string:  "https://www.gizmochina.com/wp-content/uploads/2018/09/Apple-iPhone-Xs-Max-503x503.png")) { 
image in
image.resizable()
} placeholder: {
ProgressView()
}.frame(width: 100 ,height: 100)

For this example, SwiftUI shows a ProgressView() as a placeholder first, and then the image scaled to fit in the specified frame.

--

--

TextField : A control that displays an editable text interface.

Multiple ways to observe the SwiftUI TextField value

  1. Using Closure
  2. Using onChange modifier
  3. Using Publisher(Combine)
import SwiftUI
import Combine
struct ContentView: View { @State private var Text1 = ""
@State private var Text2 = ""
@ObservedObject var viewModel = ObserveTextFieldValue()
var body: some View { //MARK: Using Closure
TextField("Enter text1", text: $Text1){ editing in
print(editing)
}onCommit: {
print("Committed")
}
//MARK: Using .onChange Modifier
TextField("Enter text2", text: $Text2).onChange(of: Text2){
text in
print(text)
}
//MARK: Using Viewmodel and Publisher(Combine)
TextField("Enter text3", text: $viewModel.value)
}}
class
ObserveTextFieldValue: ObservableObject {
@Published var value: String = ""
private var cancellables = Set<AnyCancellable>()
init() {
$value.sink(receiveValue: {val in
print(val)
}).store(in: &cancellables)
}
}

--

--

TextField is a control that displays an editable text interface.

In this blog, we’ll learn how to set the maximum limit of a text in Textfield using Combine.

The most elegant (and simple) way to set a character limit on the TextField is to use the native publisher event collect().

collect()Collects all received elements, and emits a single array of the collection when the upstream publisher finishes.

import SwiftUI
import Combine
struct ContentView: View {
@State var text = ""
var body: some View {
TextField("Set the max length", text: $text)
.font(Font.system(size: 16))
.foregroundColor(Color.blue)
.onReceive(text.publisher.collect()){
let result = String($0.prefix(240))
if text != result {
text = result
}
}
Text("\(text.count)/240 Characters")
}
}

Reference taken from,
https://stackoverflow.com/questions/56476007/swiftui-textfield-max-length

--

--

The easiest way to Sign in with Apple using SwiftUI.

SignInWithAppleButton
The view that creates the Sign in with Apple button for display.


SignInWithAppleButton
(.signIn) { request in
request.requestedScopes = [.email , .fullName]}
onCompletion: { result in
switch result { case .success(let authResults): print("Authorisation successful") case .failure(let error): print("Authorisation failed: \(error.localizedDescription)") }}

--

--