diff --git a/FiveGuyes/FiveGuyes.xcodeproj/project.pbxproj b/FiveGuyes/FiveGuyes.xcodeproj/project.pbxproj index b802574..3d19ada 100644 --- a/FiveGuyes/FiveGuyes.xcodeproj/project.pbxproj +++ b/FiveGuyes/FiveGuyes.xcodeproj/project.pbxproj @@ -596,7 +596,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.FiveNorms.FiveNorms; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; @@ -634,7 +634,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.1.0; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.FiveNorms.FiveNorms; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; diff --git a/FiveGuyes/FiveGuyes/Sources/Models/ReadingScheduleCalculator.swift b/FiveGuyes/FiveGuyes/Sources/Models/ReadingScheduleCalculator.swift index 14af7ed..e234444 100644 --- a/FiveGuyes/FiveGuyes/Sources/Models/ReadingScheduleCalculator.swift +++ b/FiveGuyes/FiveGuyes/Sources/Models/ReadingScheduleCalculator.swift @@ -34,7 +34,7 @@ struct ReadingScheduleCalculator { let dateKey = toYearMonthDayString(targetDate) if !currentReadingBook.book.nonReadingDays.map({ toYearMonthDayString($0) }).contains(dateKey) { cumulativePages += pagesPerDay - print("๐Ÿฒ๐Ÿฒ๐Ÿฒ: \(dateKey)") + print("๐Ÿฒ๐Ÿฒ๐Ÿฒ: \(dateKey), \(cumulativePages)") currentReadingBook.readingRecords[dateKey] = ReadingRecord(targetPages: cumulativePages, pagesRead: 0) } targetDate = Calendar.current.date(byAdding: .day, value: 1, to: targetDate)! @@ -59,14 +59,23 @@ struct ReadingScheduleCalculator { // MARK: ์ฝ์€ ํŽ˜์ด์ง€ ์ž…๋ ฅ ๋ฉ”์„œ๋“œ (์˜ค๋Š˜ ๋‚ ์งœ์—๋งŒ ๊ฐ’์„ ๋„ฃ์„ ์ˆ˜ ์žˆ์Œ) func updateReadingProgress(for currentReadingBook: UserBook, pagesRead: Int, from today: Date) { let dateKey = toYearMonthDayString(today) - guard var record = currentReadingBook.readingRecords[dateKey] else { return } + + // ๊ธฐ๋ก์ด ์—†์œผ๋ฉด ๊ธฐ๋ณธ๊ฐ’ ์ถ”๊ฐ€ + var record = currentReadingBook.readingRecords[dateKey, default: ReadingRecord(targetPages: 0, pagesRead: 0)] + + // nonReadingDays์—์„œ today ์ œ๊ฑฐ (dateKey๋กœ ๋น„๊ต) + if let index = currentReadingBook.book.nonReadingDays.firstIndex(where: { toYearMonthDayString($0) == dateKey }) { + currentReadingBook.book.nonReadingDays.remove(at: index) + } else { + print("์ง€์šธ ๋‚ ์งœ ์—†์Œ == ์ด๋ฏธ ํ• ๋‹น๋˜์–ด ์žˆ๋Š” ๋‚ ์ž…๋‹ˆ๋‹ค.") + } record.pagesRead = pagesRead currentReadingBook.readingRecords[dateKey] = record // lastReadDate์™€ lastPagesRead๋ฅผ ์ตœ์‹ ํ™” - currentReadingBook.lastReadDate = today - currentReadingBook.lastPagesRead = pagesRead + currentReadingBook.lastReadDate = today + currentReadingBook.lastPagesRead = pagesRead // ๋ชฉํ‘œ๋Ÿ‰๊ณผ ์‹ค์ œ ์ฝ์€ ํŽ˜์ด์ง€ ์ˆ˜๊ฐ€ ๋‹ค๋ฅธ ๊ฒฝ์šฐ ์ดํ›„ ํ• ๋‹น๋Ÿ‰ ์žฌ์กฐ์ • if record.pagesRead != record.targetPages { @@ -125,7 +134,7 @@ struct ReadingScheduleCalculator { func reassignPagesFromLastReadDate(for currentReadingBook: UserBook) { // ์ด๋ฏธ ์ฝ์—ˆ์œผ๋ฉด ์žฌ๋ถ„๋ฐฐ x if hasReadPagesToday(for: currentReadingBook) { return } - + // ๋‚จ์€ ํŽ˜์ด์ง€์™€ ์ผ์ˆ˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ƒˆ๋กญ๊ฒŒ ํ• ๋‹น๋Ÿ‰ ๊ณ„์‚ฐ let (pagesPerDay, remainderPages) = calculatePagesPerDay(for: currentReadingBook) var remainderOffset = remainderPages @@ -135,7 +144,7 @@ struct ReadingScheduleCalculator { while toYearMonthDayString(targetDate) <= toYearMonthDayString(currentReadingBook.book.targetEndDate) { let dateKey = toYearMonthDayString(targetDate) - + // ๋น„๋…์„œ์ผ์ด ์•„๋‹ˆ๋ฉด ํ• ๋‹น๋Ÿ‰์„ ์ƒˆ๋กœ ์„ค์ • if !currentReadingBook.book.nonReadingDays.map({ toYearMonthDayString($0) }).contains(dateKey) { cumulativePages += pagesPerDay @@ -161,7 +170,7 @@ struct ReadingScheduleCalculator { // ์˜ค๋Š˜ ํ• ๋‹น๋Ÿ‰์ด ์ฝํ˜”๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋ฉ”์„œ๋“œ private func hasReadPagesToday(for currentReadingBook: UserBook) -> Bool { let todayKey = toYearMonthDayString(Date()) - return currentReadingBook.readingRecords[todayKey]?.pagesRead != 0 + return currentReadingBook.readingRecords[todayKey]?.pagesRead != 0 } // MARK: - ์ดˆ๊ธฐ์— ํŽ˜์ด์ง€๋ฅผ ํ• ๋‹นํ•  ๋•Œ ํ•„์š”ํ•œ ๋ฉ”์„œ๋“œ