Share
Explore

s24 MO1013 IOS final project - The Swift Application

How to hand this in:
Do this work in Xcode or an ONLINE Swift IDE
Put all your code and screen shots illustrating the working project into a Word Document named as a Student Name Student ID and upload to Google Classroom.

Here is the project requirement description for the Library Swift model:

Project: Swift Library Management System
Objective: Develop a command-line Swift application to manage a library system. The system should handle books, patrons, and basic library operations.
Key Components:
Book:
Properties: title, author, ISBN, publication year, genre, availability status
Functionality: check out, check in, display information
Patron:
Properties: ID, name, contact information, list of checked out books
Functionality: check out book, return book, display borrowed books
Library:
Properties: collection of books, list of patrons
Functionality: add/remove books, register/remove patrons, search books, manage checkouts and returns
Detailed Requirements:
Book Management:
Add new books to the library
Remove books from the library
Update book information
Search books by title, author, or ISBN
Display all books or filter by genre/availability
Patron Management:
Register new patrons
Update patron information
Remove patrons from the system
Display patron information, including currently borrowed books
Checkout System:
Allow patrons to check out available books
Implement a limit on the number of books a patron can borrow (e.g., 5 books maximum)
Set a due date for borrowed books (e.g., 14 days from checkout)
Return System:
Process book returns
Calculate and apply late fees if the book is overdue (e.g., $0.25 per day)
Reporting:
Generate a report of all overdue books
List most popular books (most frequently borrowed)
Show patrons with outstanding fines
Data Persistence:
Implement basic data persistence (e.g., save and load library state from a file)
Technical Requirements:
Use Swift structs or classes to model Books, Patrons, and the Library
Implement appropriate methods for each struct/class to handle required functionality
Use Swift's built-in data structures (Arrays, Dictionaries) to manage collections of books and patrons
Utilize Swift's error handling mechanisms for operations that might fail (e.g., checking out an unavailable book)
Implement a simple command-line interface for user interaction
Follow Swift best practices and conventions for naming and code organization
Include comments to explain complex logic or algorithms
Implement basic unit tests for core functionality
Optional Enhancements:
Implement a reservation system for currently checked-out books
Add a recommendation system based on a patron's borrowing history
Include a simple authentication system for patrons and librarians
Implement more advanced search capabilities (e.g., fuzzy matching for titles/authors)
Deliverables:
Swift source code files
README file with instructions on how to run the application
Sample data file (if using file-based persistence)
Brief documentation outlining the structure of the code and any important design decisions
This project will help demonstrate your understanding of Swift fundamentals, including structs/classes, protocols, error handling, and working with collections, while also providing a practical application that can be extended in various ways.

Here is a starter template: Do my your own work and refer to this only as needed for ideas:
info

Here's a starter Swift solution framework for the Library Management System based on the requirements. This code provides a command-line interface for interacting with the library system:


import Foundation

// MARK: - Models

struct Book: Codable {
let isbn: String
var title: String
var author: String
var publicationYear: Int
var genre: String
var isAvailable: Bool = true
var dueDate: Date?
mutating func checkOut() {
isAvailable = false
dueDate = Calendar.current.date(byAdding: .day, value: 14, to: Date())
}
mutating func checkIn() {
isAvailable = true
dueDate = nil
}
}

struct Patron: Codable {
let id: String
var name: String
var contactInfo: String
var checkedOutBooks: [String] // ISBNs of checked out books
var fines: Double = 0
mutating func checkOutBook(_ isbn: String) {
checkedOutBooks.append(isbn)
}
mutating func returnBook(_ isbn: String) {
checkedOutBooks.removeAll { $0 == isbn }
}
mutating func addFine(_ amount: Double) {
fines += amount
}
mutating func payFine(_ amount: Double) {
fines = max(0, fines - amount)
}
}

class Library: Codable {
var books: [Book]
var patrons: [Patron]
init() {
books = []
patrons = []
}
func addBook(_ book: Book) {
books.append(book)
}
func removeBook(isbn: String) {
books.removeAll { $0.isbn == isbn }
}
func findBook(isbn: String) -> Book? {
return books.first { $0.isbn == isbn }
}
func updateBook(isbn: String, updatedBook: Book) {
if let index = books.firstIndex(where: { $0.isbn == isbn }) {
books[index] = updatedBook
}
}
func searchBooks(query: String) -> [Book] {
return books.filter { $0.title.lowercased().contains(query.lowercased()) ||
$0.author.lowercased().contains(query.lowercased()) ||
$0.isbn.lowercased().contains(query.lowercased()) }
}
func availableBooks() -> [Book] {
return books.filter { $0.isAvailable }
}
func addPatron(_ patron: Patron) {
patrons.append(patron)
}
func removePatron(id: String) {
patrons.removeAll { $0.id == id }
}
func findPatron(id: String) -> Patron? {
return patrons.first { $0.id == id }
}
func checkOutBook(isbn: String, patronId: String) throws {
guard var book = findBook(isbn: isbn), book.isAvailable else {
throw LibraryError.bookUnavailable
}
guard var patron = findPatron(id: patronId) else {
throw LibraryError.patronNotFound
}
guard patron.checkedOutBooks.count < 5 else {
throw LibraryError.checkoutLimitReached
}
book.checkOut()
patron.checkOutBook(isbn)
updateBook(isbn: isbn, updatedBook: book)
updatePatron(id: patronId, updatedPatron: patron)
}
func returnBook(isbn: String, patronId: String) throws {
guard var book = findBook(isbn: isbn), !book.isAvailable else {
throw LibraryError.bookNotCheckedOut
}
guard var patron = findPatron(id: patronId) else {
throw LibraryError.patronNotFound
}
book.checkIn()
patron.returnBook(isbn)
if let dueDate = book.dueDate, dueDate < Date() {
let daysLate = Calendar.current.dateComponents([.day], from: dueDate, to: Date()).day ?? 0
let fine = Double(daysLate) * 0.25
patron.addFine(fine)
}
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.