I’ve operate the place I am creating one of many circumstances randomly, however I would like after I begin the app It would solely generate the message as soon as and when I’ll open it once more it is going to be the identical however not completely different. Any thought how ought to I make it ?
Right here is code:
import SwiftUI
struct ListOfMessages: View {
@State non-public var isDetailViewPressed = false
let uniqueCustomer: String
let topColor: Shade
let bottomColor: Shade
var physique: some View {
Button(motion: {
isDetailViewPressed.toggle()
}) {
ZStack {
Rectangle()
.fill(LinearGradient(colours: [topColor, bottomColor], startPoint: .topLeading, endPoint: .bottomTrailing))
.cornerRadius(13)
.body(top: 120)
.padding(10)
.opacity(0.8)
VStack {
HStack {
Textual content(uniqueCustomer)
.font(.largeTitle)
.daring()
.foregroundColor(.yellow)
.padding(30)
Spacer()
}
Picture(systemName: "envelope")
.font(.largeTitle)
.foregroundColor(.yellow)
.padding(.main, 260)
.padding(.prime, -30)
}.padding(.prime, -30)
}
}
.fullScreenCover(isPresented: $isDetailViewPressed) {
DestinationView(uniqueCustomer: uniqueCustomer)
}
}
}
struct DestinationView: View {
@Setting(.presentationMode) var presentationMode
let uniqueCustomer: String
var physique: some View {
ZStack(alignment: . topLeading) {
Picture("house")
.resizable()
.ignoresSafeArea()
Button(motion: {
presentationMode.wrappedValue.dismiss()
}, label: {
Picture(systemName: "xmark")
.foregroundColor(.yellow)
.font(.largeTitle)
.padding(.main, 30)
.padding(.prime, 10)
})
Textual content(uniqueCustomer)
.foregroundColor(.yellow)
.font(.system(dimension: 40))
.daring()
.padding(.prime, 70)
.padding(.main, 30)
Textual content(makeRandomPhrase(randomNumber: Int.random(in: 0...2))) //Right here have to create a phrase solely as soon as
.foregroundColor(.white)
.font(.system(dimension: 30))
.daring()
.padding(.prime, 120)
.padding(.main, 30)
.body(width: 350)
}
}
func makeRandomPhrase(randomNumber: Int) -> String {
let makePhrase: String
var myName = "Mário"
change randomNumber {
case 0: makePhrase = "Hey (myName) I am so glad that I had seen you out. Might we go on soccer match this night? nnRegards,n(uniqueCustomer)"
case 1: makePhrase = "Hi there (myName) how are you? I have not seen you for a very long time. We must always meet someplace on the town in case you are down. nnAll the very best,n(uniqueCustomer)"
case 2: makePhrase = "Eyo (myName) what is going to we do as we speak?"
default: makePhrase = "Hey (myName) I am so glad to see you right here."
}
return makePhrase
}
}
I although about making a json file the place I’ll save the phrase after which take the phrase out. This was not working. I used to be anticipating that the phrase will generate solely as soon as for every buyer.