[ Project ] Book search APP 3

2024. 8. 9. 11:17ยทiOS_Developer/Team Project

  โ‘ก  ๋‹ด๊ธฐ ๋ฐ X ๋ฒ„ํŠผ ๊ตฌํ˜„  

 

1. ๋‹ด๊ธฐ ๋ฐ X ๋ฒ„ํŠผ์€ ํ”Œ๋กœํŒ… ๋ฒ„ํŠผ

X ์™€ ๋‹ด๊ธฐ ๋ฒ„ํŠผ์˜ ๋„ˆ๋น„ ๋น„์œจ์€ 1:3~4 

cancelButton.widthAnchor.constraint(equalTo: buttonStackView.widthAnchor, multiplier: 1/4),
cancelButton.heightAnchor.constraint(equalTo: buttonStackView.heightAnchor),

cartButton.widthAnchor.constraint(equalTo: buttonStackView.widthAnchor, multiplier: 3/4),
cartButton.heightAnchor.constraint(equalTo: buttonStackView.heightAnchor)

 

๋‹ด๊ธฐ ๋ฒ„ํŠผ์„ ํƒญ

 

ํ•ด๋‹น ์ฑ…์€ ๋‹ด์€ ์ฑ… ๋ชฉ๋ก ํ™”๋ฉด์—์„œ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋‹ฌ์€ ๋‹ซํž˜

 

[ CoreData CRUD ]

1. ์ฑ… ์ƒ์„ธ ํ™”๋ฉด์—์„œ ๋ฐ์ดํ„ฐ ์ €์žฅ (Create):

๋‹ด๊ธฐ ๋ฒ„ํŠผ ํด๋ฆญ > CoreData์— ์ƒˆ๋กœ์šด ์ฑ… ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ƒ์„ฑ, ์ €์žฅ

2. ์ฑ… ๋ชฉ๋ก ํ™”๋ฉด์—์„œ ๋ฐ์ดํ„ฐ ์กฐํšŒ (Read):

์•ฑ ์‹œ์ž‘ ์‹œ, CoreData์—์„œ ์ €์žฅ๋œ ์ฑ… ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์™€์„œ ๋ชฉ๋ก์„ ํ‘œ์‹œ

3. ์ฑ… ๋ชฉ๋ก์—์„œ ๋ฐ์ดํ„ฐ ์‚ญ์ œ (Delete):

์‚ญ์ œ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ CoreData์—์„œ ํ•ด๋‹น ์ฑ… ์—”ํ‹ฐํ‹ฐ๋ฅผ ์‚ญ์ œ

 

์ฑ…์ •๋ณด๋‚˜ ๊ณ ๊ฐ์ •๋ณด ์—…๋ฐ์ดํŠธ๊ฐ€ ์—†๊ธฐ์—

U๋Š” ์ด ํ”„์ ์—์„  ํ•„์š”๊ฐ€ ์—†๋‹ค!

 

3. X ๋ฒ„ํŠผ์„ ํƒญ ํ•˜๋ฉด ๋ชจ๋‹ฌ์€ ๋‹ซํž˜

 

1. Core Data ์ปจํ…์ŠคํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ:

Core Data ์ปจํ…์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐฉ๋ฒ•์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. 

2. ๋‹ด๊ธฐ ๋ฒ„ํŠผ ํด๋ฆญ ์•ก์…˜ ์ถ”๊ฐ€:

 ๋‹ด๊ธฐ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•  ๋•Œ ISBN์„ Core Data์— ์ €์žฅํ•˜๋„๋ก ๊ตฌํ˜„

 

 

๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์•Œ๋Ÿฟ์ฐฝ ๋„์šฐ๊ณ  Core Data์— ์ฑ…๋ฒˆํ˜ธ ์ €์žฅ ์™„๋ฃŒ

@objc private func cartButtonTapped() {
        guard let book = book else {
            print("Book is nil")
            return
        }
        
        if let isbn = book.isbn {
            let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
            
            let bookNum = BookNum(context: context)
            bookNum.isbn = isbn
            
            do {
                try context.save()
                print("Book saved to Core Data")
                
                let alert = UIAlertController(title: "์„ฑ๊ณต", message: "์ฑ…์ด ๋‹ด๊ธฐ ๋ชฉ๋ก์— ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "ํ™•์ธ", style: .default))
                self.present(alert, animated: true)
                
            } catch {
                print("Failed to save book: \(error.localizedDescription)")
            }
        } else {
            print("ISBN is nil")
        }
    }

 

 

  โ‘ข ์„ ํƒ ๋ฐ ์ถ”๊ฐ€ ๊ตฌํ˜„์‚ฌํ•ญ  

1.  ์ฑ… ์ƒ์„ธ ํ™”๋ฉด์€ ์ปจํ…์ธ  ์–‘์— ๋”ฐ๋ผ ์Šคํฌ๋กค ํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ตฌํ˜„

์ฆ‰, ์Šคํฌ๋กค๊ณผ ์ƒ๊ด€์—†์ด ํ•ญ์ƒ ํ™”๋ฉด ์œ„์— ๋…ธ์ถœ๋˜์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.

 

2. ๋‹ด๊ธฐ ๋ฒ„ํŠผ ํ›„ ๋ชจ๋‹ฌ ์ด ๋‹ซํžŒ ํ›„ ๋‹ด์€ ์ฑ… ๋ชฉ๋ก์— ์ถ”๊ฐ€๋˜์—ˆ๋‹ค๋Š” alert์ฐฝ ๋„์šฐ๊ธฐ

 

Delegate ํŒจํ„ด์„ ํ™œ์šฉํ•ด๋ด…๋‹ˆ๋‹ค.

 

 

 ๐Ÿ  3 - 2. ๋‹ด๊ธฐ ํ™”๋ฉด  

  โ‘   ๋‹ด๊ธฐ ํ™”๋ฉด UI ๊ตฌํ˜„  

 

์•ฑ์„ ์ข…๋ฃŒํ•˜๊ณ  ๋‹ค์‹œ ์‹œ์ž‘ํ•ด๋„ ๋‹ด์€ ์ฑ… ๋ชฉ๋ก์€ ๋‚จ์•„์žˆ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.

์ „์ฒด ์‚ญ์ œ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๋‹ด์•˜๋˜ ๋ชจ๋“  ์ฑ…์ด ์ง€์›Œ์ง‘๋‹ˆ๋‹ค.

 

 

  ์Šค์™€์ดํ”„ ๋“ฑ์˜ ๋ฐฉ์‹์„ ํ†ตํ•˜์—ฌ ๋‹ด์€ ์ฑ… ๊ฐœ๋ณ„์‚ญ์ œ  

 

 private func deleteBook(at indexPath: IndexPath) {
        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
        
        let managedContext = appDelegate.persistentContainer.viewContext
        let fetchRequest: NSFetchRequest<BookNum> = BookNum.fetchRequest()
        
        do {
            let bookEntities = try managedContext.fetch(fetchRequest)
            let bookToDelete = bookEntities[indexPath.item]
            managedContext.delete(bookToDelete)
            try managedContext.save()
            
            books.remove(at: indexPath.item)
            collectionView.deleteItems(at: [indexPath])
        } catch let error as NSError {
            handleError(error)
        }
    }
    
    
    func didSwipeCell(_ cell: CartListCell) {
        if let indexPath = collectionView.indexPath(for: cell) {
            showDeleteConfirmation(for: indexPath)
        }
    }
    
    private func showDeleteConfirmation(for indexPath: IndexPath) {
        let alertController = UIAlertController(title: "์ฑ… ์‚ญ์ œ", message: "์ด ์ฑ…์„ ์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?", preferredStyle: .alert)
        
        let deleteAction = UIAlertAction(title: "์‚ญ์ œ", style: .destructive) { [weak self] _ in
            self?.deleteBook(at: indexPath)
        }
        let cancelAction = UIAlertAction(title: "์ทจ์†Œ", style: .cancel, handler: nil)
        
        alertController.addAction(deleteAction)
        alertController.addAction(cancelAction)
        
        present(alertController, animated: true, completion: nil)
    }

 

 private func addSwipeGestureRecognizer() {
        let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe))
        swipeGesture.direction = .left // Set swipe direction (e.g., left swipe)
        contentView.addGestureRecognizer(swipeGesture)
    }
    
    @objc private func handleSwipe() {
        delegate?.didSwipeCell(self)
    }

 

์ถ”๊ฐ€๋กœ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š” ๋ถ€๋ถ„

โ–ท ๋‹ด๊ธฐ ๋ฒ„ํŠผ์„ ํƒญํ•˜๋ฉด alert์ฐฝ์ด ๋œจ๊ฒŒ ๊ตฌํ˜„์ด ๋˜์–ด ์žˆ์Œ alert๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์ƒ์„ธ์ •๋ณด ๋ชจ๋‹ฌ์€ ๋‹ซํžˆ๋„๋ก ๊ตฌํ˜„ ํ•„์š”

โ–ท X ๋ฒ„ํŠผ์„ ํƒญ ํ•˜๋ฉด ๋ชจ๋‹ฌ์€ ๋‹ซํžˆ๋„๋ก ๊ตฌํ˜„ ํ•„์š”

โ–ท ์ถ”๊ฐ€ ๋ฒ„ํŠผ์„ ํ†ตํ•ด ๊ฒ€์ƒ‰ ํ™”๋ฉด์œผ๋กœ ์ „ํ™˜ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

โ–ท  Level 5 - ๋ฌดํ•œ ์Šคํฌ๋กค ๊ธฐ๋Šฅ ๊ตฌํ˜„, MVVM ๋ฆฌํŒฉํ† ๋ง (์„ ํƒ)

โ–ท ๊ฒ€์ƒ‰๋œ ๊ฒฐ๊ณผ๋ฅผ ์ตœ์‹ ์ˆœ, ์ •ํ™•๋„ ์ˆœ์œผ๋กœ ์ •๋ ฌ  

โ–ท 1ํŽ˜์ด์ง€๋‹น 20๊ฐœ์˜ ๊ฒฐ๊ณผ๋ฌผ ๋„์ถœ   

โ–ท ๊ฒ€์ƒ‰ ํ•„๋“œ ์ œํ•œ ํƒ€์ดํ‹€, ์ €์ž  


 

728x90

'iOS_Developer > Team Project' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[TeamProject] ํ”„๋กœ์ ํŠธ ๊ธฐํš _ 1์ผ์ฐจ  (0) 2024.08.23
[ Project ] ๋‹จ์–ด์žฅ ์–ดํ”Œ ์˜ค๋ฅ˜ ํ•ด๊ฒฐ  (0) 2024.08.13
[ Project ] ๋‹จ์–ด์žฅ ์–ดํ”Œ ๊ธฐํš  (0) 2024.08.13
[ Project ] Book search APP_2  (0) 2024.08.08
[ Project ] Book search APP  (0) 2024.08.01
'iOS_Developer/Team Project' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [ Project ] ๋‹จ์–ด์žฅ ์–ดํ”Œ ์˜ค๋ฅ˜ ํ•ด๊ฒฐ
  • [ Project ] ๋‹จ์–ด์žฅ ์–ดํ”Œ ๊ธฐํš
  • [ Project ] Book search APP_2
  • [ Project ] Book search APP
JJOOEE
JJOOEE
Byeockdol๐Ÿˆ‍โฌ› _ IT / PM
  • JJOOEE
    Byeockdol๐Ÿˆ‍โฌ›
    JJOOEE
  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
    • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (32)
      • PM (3)
        • TIL & WIL (3)
        • Article (0)
      • ๋ฐ์ดํ„ฐ ๋ถ„์„ (0)
      • iOS_Developer (28)
        • iOS (4)
        • UIkit (3)
        • swift (3)
        • Collaboration Tools (1)
        • ๋ฉด์ ‘์ค€๋น„ (5)
        • Team Project (12)
      • Byeockdol๐Ÿˆ‍โฌ› (1)
  • ๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

    • ํ™ˆ
    • ํƒœ๊ทธ
    • ๋ฐฉ๋ช…๋ก
  • ๋งํฌ

    • github
  • ๊ณต์ง€์‚ฌํ•ญ

  • ์ธ๊ธฐ ๊ธ€

  • ํƒœ๊ทธ

    ๊ธฐํš
    ํ”„๋กœ์ ํŠธ
    project
    swift
    ๊ต์œกpm
    ๊ฐœ๋ฐœ์ž ๋ฉด์ ‘์ค€๋น„
    it๊ณ ์–‘์ด
    API
    swfit์ž๋ฃŒํ˜•
    uikit
    ioskakaomap
    ์นด์นด์˜ค๋งต์ดˆ๊ธฐ์„ค์ •
    ios
    aed api
    Til
    ๋™๊ธฐ๋น„๋™๊ธฐ
    ๊ต์œก์šด์˜๋งค๋‹ˆ์ €
    rxswiftํ† ๊ธ€
    ๊ฐœ๋ฐœ์ž๋ฉด์ ‘์ค€๋น„
    ์ž๋ฃŒํ˜•
    ์นด์นด์˜ค๋งตAPI
    ๋ฒฝ๋Œ์ด
    ios๋ฉด์ ‘์ค€๋น„
    ioskakaomapapi
    ์นด์นด์˜ค๋งตapi์‚ฌ์šฉํ•˜๊ธฐ
    ios๋ฌธ๋ฒ•
    ์ฝ”๋“œ๋กœ๋งŒ ์นด์นด์˜ค๋งต
    kakaomappoi
    pm
    ๊ฐœ๋ฐœ์ž
  • ์ตœ๊ทผ ๋Œ“๊ธ€

  • ์ตœ๊ทผ ๊ธ€

  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.3
JJOOEE
[ Project ] Book search APP 3
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”