-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix [#80] 소식 탭 오류 수정 및 배지 구현, 알림 탭 프로필 이동 구현 #91
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8338598
[Fix] #80 - 공지사항 페이지 시간 잘림 현상 수정
JinUng41 01bec7c
[Feat] #80 - 소식 탭 뉴스, 공지사항 배지 구현
JinUng41 e4e3c34
[Chore] #80 - 반복되는 숫자 상수화
JinUng41 e340125
[Chore] #80 - 빈 줄 삭제
JinUng41 056ded6
[Refactor] #80 - 알림 탭 활동 페이지 알림 터치 시 이동 로직 구현 및 폴더링
JinUng41 a26fbc1
[Chore] #80 - 탭바 상단 경계선 추가
JinUng41 e38b3ef
[Chore] #80 - 불필요한 코드 삭제
JinUng41 4a9ad06
Merge branch 'develop' of https://github.com/Team-Wable/WABLE-iOS int…
JinUng41 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Wable-iOS/Global/Shared/UserDefaults/CodableSerializable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// CodableSerializable.swift | ||
// Wable-iOS | ||
// | ||
// Created by 김진웅 on 1/7/25. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol Serializable { | ||
func serialize(_ value: Encodable) throws -> Data | ||
} | ||
|
||
protocol Deserializable { | ||
func deserialize<T: Decodable>(_ type: T.Type, from data: Data) throws -> T | ||
} | ||
|
||
typealias CodableSerializable = Serializable & Deserializable | ||
|
||
|
||
// MARK: - JSONSerializer | ||
|
||
struct JSONSerializer: CodableSerializable { | ||
private let encoder = JSONEncoder() | ||
private let decoder = JSONDecoder() | ||
|
||
func serialize(_ value: any Encodable) throws -> Data { | ||
try encoder.encode(value) | ||
} | ||
|
||
func deserialize<T: Decodable>(_ type: T.Type, from data: Data) throws -> T { | ||
try decoder.decode(type, from: data) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Wable-iOS/Global/Shared/UserDefaults/UserDefaultsKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// UserDefaultsKey.swift | ||
// Wable-iOS | ||
// | ||
// Created by 김진웅 on 1/7/25. | ||
// | ||
|
||
import Foundation | ||
|
||
/// UserDefaults에 접근하기 위한 Key의 타입을 정의하는 프로토콜 | ||
/// | ||
/// 아래와 같이, 열거형으로 구현한다. | ||
/// | ||
/// ```swift | ||
/// enum UserDefaultsKeys: UserDefaultsKey { | ||
/// case userInfo | ||
/// | ||
/// var value: String { | ||
/// switch self{ | ||
/// case .userInfo: | ||
/// return "userInfo" | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
protocol UserDefaultsKey: Hashable, CaseIterable { | ||
var value: String { get } | ||
} |
71 changes: 71 additions & 0 deletions
71
Wable-iOS/Global/Shared/UserDefaults/UserDefaultsManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// UserDefaultsManager.swift | ||
// Wable-iOS | ||
// | ||
// Created by 김진웅 on 1/7/25. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol UserDefaultsManager { | ||
func save<T: Codable>(_ value: T, forKey key: any UserDefaultsKey) | ||
func load<T: Codable>(forKey key: any UserDefaultsKey, as type: T.Type) -> T? | ||
func remove(forKey keys: any UserDefaultsKey...) | ||
func removeAll() | ||
} | ||
|
||
final class UserDefaultsManagerImpl: UserDefaultsManager { | ||
private let serializer: CodableSerializable | ||
private let userDefaults = UserDefaults.standard | ||
|
||
init(serializer: CodableSerializable = JSONSerializer()) { | ||
self.serializer = serializer | ||
} | ||
|
||
func save<T: Codable>(_ value: T, forKey key: any UserDefaultsKey) { | ||
if isPrimitiveType(T.self) { | ||
userDefaults.set(value, forKey: key.value) | ||
return | ||
} | ||
|
||
do { | ||
let data = try serializer.serialize(value) | ||
userDefaults.set(data, forKey: key.value) | ||
} catch { | ||
print("Failed to encode data for key \(key.value): \(error)") | ||
} | ||
} | ||
|
||
func load<T: Codable>(forKey key: any UserDefaultsKey, as type: T.Type) -> T? { | ||
if isPrimitiveType(T.self) { | ||
return userDefaults.object(forKey: key.value) as? T | ||
} | ||
|
||
guard let data = userDefaults.data(forKey: key.value) else { | ||
return nil | ||
} | ||
|
||
do { | ||
return try serializer.deserialize(type, from: data) | ||
} catch { | ||
print("Failed to decode data for key \(key.value): \(error)") | ||
return nil | ||
} | ||
} | ||
|
||
/// 특정 키 삭제 | ||
func remove(forKey keys: any UserDefaultsKey...) { | ||
keys.forEach { self.userDefaults.removeObject(forKey: $0.value) } | ||
} | ||
|
||
/// 모든 데이터 삭제 | ||
func removeAll() { | ||
userDefaults.dictionaryRepresentation().forEach { (key, _) in | ||
userDefaults.removeObject(forKey: key) | ||
} | ||
} | ||
|
||
private func isPrimitiveType<T>(_ type: T.Type) -> Bool { | ||
return type is Int.Type || type is Double.Type || type is Float.Type || type is Bool.Type || type is String.Type | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// InfoCountDTO.swift | ||
// Wable-iOS | ||
// | ||
// Created by 김진웅 on 1/7/25. | ||
// | ||
|
||
import Foundation | ||
|
||
struct InfoCountDTO: Codable { | ||
let newsCount: Int | ||
let noticeCount: Int | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case newsCount = "newsNumber" | ||
case noticeCount = "noticeNumber" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 이해한 바로는 UserDefault에 구조체를 저장할 수 있게끔 만들어주신 것 같은데 맞을 까요?! 너무 고생 많으셨습니다!!👍🏻👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 맞습니다.