iOS 알람앱 타이머기능 구현및 업그레이드: CoreData 통합 및 UX 개선

호씨·2025년 1월 8일
0

iOS 알람앱 타이머기능 구현및 업그레이드: CoreData 통합 및 UX 개선 🚀

소개 💡

기존의 기본적인 타이머 앱에 CoreData를 통합하고 UX를 개선하는 과정을 정리하였다. 데이터 영속성 구현과 사용자 경험 향상에 중점을 두었다.

주요 업그레이드 내용 ⚙️

1. CoreData 통합

  • 타이머 데이터의 영구 저장 기능 구현
  • TimerCoreDataManager 싱글톤 패턴 적용
  • 데이터 CRUD 작업 메서드 구현

2. UI/UX 개선

타이머명 입력 필드의 가시성을 개선하였다:

labelTextField.attributedPlaceholder = NSAttributedString(
    string: "타이머명",
    attributes: [NSAttributedString.Key.foregroundColor: UIColor.gray]
)

리셋 기능을 강화하였다:

@objc private func resetButtonTapped() {
    stopTimer()
    hours = 0
    minutes = 0
    seconds = 0
    updateTimerLabel()
    labelTextField.text = ""  // 텍스트필드 초기화 추가
    playPauseButton.setImage(UIImage(systemName: "play.fill"), for: .normal)
}

3. 데이터 영속성 구현 📊

CoreData 매니저 클래스를 구현하여 데이터 관리를 체계화하였다:

class TimerCoreDataManager {
    static let shared = TimerCoreDataManager()
    
    // CRUD Operations
    func saveTimer(name: String, hours: Int, minutes: Int, seconds: Int) {
        let timer = TimerItem(context: context)
        timer.name = name
        timer.hours = Int16(hours)
        timer.minutes = Int16(minutes)
        timer.seconds = Int16(seconds)
        timer.createdAt = Date()
        
        saveContext()
    }
    
    func fetchTimers() -> [TimerItem] {
        let request: NSFetchRequest<TimerItem> = TimerItem.fetchRequest()
        request.sortDescriptors = [NSSortDescriptor(key: "createdAt", ascending: false)]
        
        do {
            return try context.fetch(request)
        } catch {
            print("타이머 가져오기 실패: \(error)")
            return []
        }
    }
}

4. 최근 타이머 표시 기능 📱

테이블뷰를 활용하여 저장된 타이머 목록을 구현하였다:

extension TimerView: UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "TimerCell", for: indexPath)
        cell.backgroundColor = .clear
        cell.textLabel?.textColor = .white
        
        let timerItem = timerItems[indexPath.row]
        let duration = String(format: "%02d:%02d:%02d",
                            timerItem.hours,
                            timerItem.minutes,
                            timerItem.seconds)
        
        cell.textLabel?.text = "\(timerItem.name ?? "Unknown")     \(duration)"
        
        return cell
    }
}

개선된 기능 ✨

1. 타이머 설정 저장

  • CoreData를 활용한 타이머 데이터 영구 저장
  • 앱 재실행 시에도 설정 유지

2. 최근 타이머 목록

  • 저장된 타이머를 시간순 정렬
  • 이전 타이머 설정 빠른 확인

3. 향상된 사용자 경험

  • 통합 리셋 기능
  • 가시성이 개선된 입력 필드
  • 직관적인 UI 구성

향후 개선 계획 🎯

  1. 기능 추가

    • 타이머 종료 시 알림 기능
    • 저장된 타이머 수정 기능
    • 스와이프 삭제 기능
    • 음악 설정
    • 시간 빼기 기능 추가
  2. UI/UX 개선

    • 애니메이션 효과 추가
profile
이것저것 많이 해보고싶은 사람

0개의 댓글

관련 채용 정보