Post

Replies

Boosts

Views

Activity

Navigation Bar back button delete
So I'm making this app and realised I have two back buttons. From the very first view, when I enter the second view and enter the third view from the second view, I have two back buttons, the very first page back button and the second back button. How do I get rid of the very first back button? This is the code for the second view. If the first view's code is quite long so if needed, please ask me Thank you import SwiftUI struct MovieView: View { @Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode> var body: some View { NavigationView{ VStack{ List{ //Your Name Block NavigationLink { YourNameView() } label: { VStack{ Image("your name") .resizable() .aspectRatio(contentMode: .fill) .cornerRadius(20) Text("Your Name") .fontWeight(.bold) .font(.system(size:20)) } .padding() .background(Image("beige")) } //notting hill block NavigationLink { NottingHillView() } label: { VStack{ Image("notting hill") .resizable() .aspectRatio(contentMode: .fill) .cornerRadius(20) Text("Notting Hill") .fontWeight(.bold) .font(.system(size:20)) } .background(Image("beige")) .padding() } //notting hill block NavigationLink { //Love_OtherDrugsView() } label: { VStack{ Image("love and other drugs") .resizable() .aspectRatio(contentMode: .fill) .cornerRadius(20) Text("Love & Other Drugs") .fontWeight(.bold) .font(.system(size:20)) } .padding() .background(Image("beige")) } } .navigationTitle("Movies") Spacer() Button { } label: { VStack{ Image(systemName: "plus.circle.fill") .resizable() .scaledToFit() .frame(width:24, height:24) .foregroundColor(Color.red) Text("Add movie") .foregroundColor(Color.red) } } } } } struct MovieView_Previews: PreviewProvider { static var previews: some View { MovieView() } } }
3
0
686
Jul ’23
Using Textfield to make an instance
Hello So essentially I want to create an instance of a class using the TextField input class Movie: ObservableObject{ @Published var name:String = "" @Published var director:String = "" @Published var stars:Double = 0.0 @Published var review:String = "" func setName(theName:String){ self.name = theName } func setDirector(theDirector:String){ self.director = theDirector } func setStars(theStars:Double){ self.stars = theStars } func setReview(theReview:String){ self.review = theReview } } so this is the class that I want to initialise and I want to get a value from the struct below and store it in variables in this class struct BottomSheetView:View{ @StateObject var newMovie = Movie() var body: some View{ VStack(alignment: .leading){ Text("Add Movie") .fontWeight(.bold) .font(.system(size:30)) .padding() TextField("Movie name", text: ???? } } } I want to get a String from the textfield above and store to var name:String in the Movie class How do I do this?
2
0
470
Aug ’23
Using observableobject in a different View
Hello, I want to use this observableobject that I made in SavingMovieView in MovieView How do I do this...? import SwiftUI import CloudKit struct MovieView: View { @State var showingSavingMovieSheet:Bool = false var body: some View { NavigationView{ ZStack(alignment: .bottomTrailing){ //the list of movies List{ //ForEach(vm.movies) { movies in //} //Your Name Block NavigationLink { // } label: { VStack{ Image("your name") .resizable() .aspectRatio(contentMode: .fill) .cornerRadius(20) Text("Your Name") .fontWeight(.bold) .font(.system(size:20)) } .padding() .background(Image("beige")) } //notting hill block NavigationLink { NottingHillView() } label: { VStack{ Image("notting hill") .resizable() .aspectRatio(contentMode: .fill) .cornerRadius(20) Text("Notting Hill") .fontWeight(.bold) .font(.system(size:20)) } .background(Image("beige")) .padding() } //notting hill block NavigationLink { //Love_OtherDrugsView() } label: { VStack{ Image("love and other drugs") .resizable() .aspectRatio(contentMode: .fill) .cornerRadius(20) Text("Love & Other Drugs") .fontWeight(.bold) .font(.system(size:20)) } .background(Image("beige")) .padding() } } .scrollContentBackground(.hidden) .background(Image("beige")) Button { showingSavingMovieSheet.toggle() } label: { Image(systemName: "plus.circle.fill") .font(.system(size: 70)) .foregroundColor(.accentColor) .shadow(color: .gray, radius: 0.2, x: 1, y: 1) } .padding() .sheet(isPresented: $showingSavingMovieSheet) { SavingMovieView(vm: SavingMovieViewModel(container: CKContainer.default())) .presentationDetents([.fraction(0.5)]) } } .edgesIgnoringSafeArea(.bottom) .toolbar { ToolbarItem(placement: .principal){ Text("Movies") .font(Font.custom("Titan One",size:50)) .bold() .foregroundColor(Color.accentColor) } } } } } struct MovieView_Previews: PreviewProvider { static var previews: some View { MovieView() } } struct SavingMovieView: View { //making an object from the viewModel @StateObject private var vm: SavingMovieViewModel @State private var title: String = "" @State private var director: String = "" @State private var stars: String = "" @State private var review: String = "" @Environment(\.dismiss) var dismiss init(vm: SavingMovieViewModel){ _vm = StateObject(wrappedValue: vm) } var body: some View { VStack{ Text("Add movie") .bold() .foregroundColor(Color.accentColor) .font(Font.custom("Titan One",size:50)) TextField("Movie Title", text: $title) .textFieldStyle(.roundedBorder) TextField("Director Name", text: $director) .textFieldStyle(.roundedBorder) TextField("Number of rating stars", text: $stars) .textFieldStyle(.roundedBorder) TextField("Description", text: $review) .textFieldStyle(.roundedBorder) Button { vm.saveMovie(title: title, director: director, stars: stars, review: review) dismiss() } label: { Text("Save") } } .padding() } } struct SavingMovieView_Previews: PreviewProvider { static var previews: some View { SavingMovieView(vm: SavingMovieViewModel(container: CKContainer.default())) } }
2
0
577
Aug ’23
Cloudkit saving error
Hello, I recently started learning Swift and now I'm using Cloudkit to store user information. I kinda have no idea what I'm doing but I watched this youtube tutorial to save user data and display it in UI instantly with DispatchQueue.main.async but it keeps throwing me an error, saying "No exact matches in call to instance method 'save'" What I want to do is I want users to save a new record and I want this record to be updated instantly and be displayed on the screen. How could I fix this? import Foundation import CloudKit enum RecordType:String { case movie = "Movie" } class SavingMovieViewModel : ObservableObject{ private var database :CKDatabase private var container : CKContainer @Published var movies: [SavingMovieModel] = [] init(container: CKContainer){ self.container = container self.database = container.publicCloudDatabase } func saveMovie(title:String, director: String, stars:String, review: String){ let record = CKRecord(recordType: RecordType.movie.rawValue) let movie = Movie(theTitle: title, theDirector: director, theStars: stars, theReview: review) record.setValuesForKeys(movie.toDictionary()) // saving self.database.save(record) { newRecord, error in. //<-- here is where the error is :( if let error = error{ print(error) } else{ if let newRecord = newRecord{ //<-- this bit is the problem. i need the new record added to be displayed instantly if let movie = Movie.fromRecord(newRecord){ DispatchQueue.main.async { self.movies.append(SavingMovieModel(Movie: movie)) } } } } } } func whatMovies(){ //creating an array of movies var movies: [Movie] = [] let query = CKQuery(recordType: RecordType.movie.rawValue, predicate: NSPredicate(value: true)) database.fetch(withQuery: query) { result in switch result{ case.success(let result): result.matchResults.compactMap{$0.1} .forEach{ switch $0 { case.success(let record): if let movie = Movie.fromRecord(record){ movies.append(movie) } case.failure(let error): print(error) } } DispatchQueue.main.async { self.movies = movies.map(SavingMovieModel.init) } case.failure(let error): print(error) } } } } struct SavingMovieModel{ let movie: Movie var movieId :CKRecord.ID?{ movie.movieId } var title:String{ movie.title } var director:String{ movie.director } var stars:String{ movie.stars } var review:String{ movie.review } } This is the Movie struct for Movie objects import Foundation import CloudKit struct Movie{ var movieId: CKRecord.ID? var title:String var director:String var stars:String var review:String init(movieId: CKRecord.ID? = nil, theTitle:String, theDirector:String, theStars:String, theReview:String){ self.title = theTitle self.director = theDirector self.stars = theStars self.review = theReview self.movieId = movieId } func toDictionary() -> [String:Any]{ return ["title": title, "director" :director, "stars":stars, "review": review] } static func fromRecord(_ record :CKRecord) -> Movie? { guard let title = record.value(forKey:"title") as? String, let director = record.value(forKey:"director") as? String, let stars = record.value(forKey:"stars") as? String, let review = record.value(forKey:"review") as? String else{ return nil } return Movie(movieId: record.recordID, theTitle: title, theDirector: director, theStars: stars, theReview: review) } }
3
0
959
Aug ’23
Passing a model's string value into different view using navigationDesitnation
I'm making a to-do list app and I have an ItemModel which just stores the title(String) and boolean. So from the list, I want to be able to click on the title and push that title(String value) into a different view How can I do this? Model import Foundation struct ItemModel: Identifiable, Hashable{ let id: String = UUID().uuidString let title:String } The List List { ForEach(items) {item in NavigationLink(item.title, value: item) } .navigationDestination(for: String.self) { toDoItem SpecificItemView(item: toDoItem.title) }
1
0
343
Dec ’23
Appstore connect Waiting for Review
My simple app got initially rejected for "We need additional time to evaluate your submission and Apple Developer Program account. Your submission status will appear as "Rejected" in App Store Connect while we investigate. However, we do not require a revised binary or additional information from you at this time." I realised I hadn't agreed to one of the agreements so I did that and resubmitted and now it's just been stuck at Waiting for Review for 5 days... Should I just delete it and publish the app again because I need this app approved asap.... or would I just have to wait?
2
0
480
Jan ’24