0% found this document useful (0 votes)
4 views3 pages

Document 1

Uploaded by

Animesh Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Document 1

Uploaded by

Animesh Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SHrimad Rajchandra Institute of Management and Computer Applicatio, UTU

CS8028:Mobile application Development using ios


Set-B

//
// ContentView.swift
// Exam1
//
// Created by Yash on 12/4/24.
//

import SwiftUI

struct Movie: Identifiable {


let id = UUID()
var title: String
var genre: String
var releaseYear: String
var synopsis: String
}

struct ContentView: View {


@State private var movies: [Movie] = [
Movie(title: "Inception", genre: "Sci-Fi", releaseYear: "2010", synopsis: "A skilled thief is offered a chance
to have his past crimes forgiven."),
Movie(title: "The Dark Knight", genre: "Action", releaseYear: "2008", synopsis: "Batman sets out to
dismantle the remaining criminal organizations."),
Movie(title: "Titanic", genre: "Romance", releaseYear: "1997", synopsis: "A romance blossoms aboard the
ill-fated Titanic."),
Movie(title: "The Matrix", genre: "Sci-Fi", releaseYear: "1999", synopsis: "A hacker discovers a dystopian
reality."),
Movie(title: "Forrest Gump", genre: "Drama", releaseYear: "1994", synopsis: "A man with a low IQ
experiences extraordinary life events.")
]
@State private var isAddingNewMovie = false

var body: some View {


NavigationView {
VStack {
Text("MyMediaVault")
.font(.largeTitle)
.fontWeight(.bold)
.padding()
.animation(.easeInOut(duration: 1.5), value: true)

List(movies) { movie in
NavigationLink(destination: MovieDetailView(movie: movie)) {
Text(movie.title)
}
}
Button(action: {
isAddingNewMovie = true
}) {
Text("Add Movie")
.foregroundColor(.white)
.padding()
.background(Color.blue)
.cornerRadius(8)
}
.padding()
}
.navigationTitle("Movies")
.sheet(isPresented: $isAddingNewMovie) {
AddMovieView(movies: $movies)
}
}
}
}

struct MovieDetailView: View {


let movie: Movie

var body: some View {


VStack(spacing: 20) {
Text(movie.title)
.font(.largeTitle)
.fontWeight(.bold)
Text("Genre: \(movie.genre)")
Text("Release Year: \(movie.releaseYear)")
Text("Synopsis: \(movie.synopsis)")
.padding()
Spacer()
}
.padding()
.navigationTitle("Movie Details")
}
}

struct AddMovieView: View {


@Binding var movies: [Movie]
@Environment(\.dismiss) var dismiss

@State private var title = ""


@State private var genre = ""
@State private var releaseYear = ""
@State private var synopsis = ""

var body: some View {


NavigationView {
Form {
TextField("Title", text: $title)
TextField("Genre", text: $genre)
TextField("Release Year", text: $releaseYear)
TextField("Synopsis", text: $synopsis)
}
.navigationTitle("Add New Movie")
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Cancel") {
dismiss()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button("Add") {
let newMovie = Movie(title: title, genre: genre, releaseYear: releaseYear, synopsis: synopsis)
movies.append(newMovie)
dismiss()
}
}
}
}
}
}

#Preview {
ContentView()
}

You might also like