-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] #554 - 피드작성뷰 내 이미지 첨부 기능 UI 구현 및 전반적인 서버 연결 #570
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
Conversation
ena-isme
left a comment
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.
수고하셨습니다! 이미지 기능은 정말 신세계네요 ,,,
코드에 대한 코멘트만 남겼고,
시뮬로 확인 후 한 번 더 코리 하도록 하겠습니다 :)
| func compressImages(_ images: [UIImage], | ||
| maxImageSize: Int = MultipartConstants.maxImageSize) -> [Data] { | ||
| // 압축된 이미지 파일 배열 | ||
| var compressedDatas: [Data] = [] | ||
|
|
||
| for (index, image) in images.enumerated() { | ||
|
|
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.
W2
현재 해당 함수를 서버 단에서 호출하고 있는데, MainThread 에서 호출하고 있는 것으로 보입니다.
- 백그라운드 에서 처리할 수는 없을까요?
- 현재 for 문 안의 로직이 동기처리되고 있어 PR 작성해주신 대로 속도가 절감되고 있는 것 같습니다. 각각의 이미지를 병렬로 비동기 처리할 수는 없을까요?
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.
-
그렇네요!
.observe(on: MainScheduler.instance)가 붙어있단 생각을 못했네요 하하
이미지 압축 함수만 따로 빼서GCD로 비동기 처리하여 백그라운드에서 처리할 수 있도록 하면 될 것 같아요! -
해보겠습니닷! 찾아보니 DispatchGroup, async let 등등 구현 방법이 꽤 있는 것 같네요. 👍
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.
일단 해당 테스크도 다음 #571 이슈로 넘겨서 작업할게요!
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.
W3
withThrowingTaskGroup으로 작성하면 오류 처리를 일괄적으로 할 수 있어서 좋더라구요 !! 전에 프로젝트 할 때 사용했던 코드 첨부합니당!.!
/// SwiftUI용으로 새로 나온 PhotosPicker 를 사용할 때 편하게 이미지를 업로드 할 수 있는 함수
func postPhotosPickerItem(path: String, imageName: String, item: PhotosPickerItem) async throws -> String {
guard let data = try? await item.loadTransferable(type: Data.self) else {
throw FirebaseError.encodingFailed
}
let imagePath = "\(path)/\(imageName).jpg"
return try await postData(path: imagePath, data: data)
}
/// 여러 PhotosPickerItem을 동시에 업로드 할때. post 코드는 병렬로 호출되어서 동시에 진행된다.
func postPhotosPickerItems(path: String, imageNames: [String], items: [PhotosPickerItem]) async throws -> [String] {
var results = Array(repeating: "", count: items.count)
try await withThrowingTaskGroup(of: (Int, String).self) { group in
for (index, item) in items.enumerated() {
group.addTask {
let url = try await postPhotosPickerItem(path: path, imageName: imageNames[index], item: item)
return (index, url)
}
}
for try await (index, url) in group {
results[index] = url
}
}
return results
}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.
감사합니다. 다음 이슈에 써놓고 활용해볼게요!!! 👍🤩
...S/Source/Presentation/FeedEdit/FeedEditView/FeedEditAssistantView/FeedEditAddImageView.swift
Show resolved
Hide resolved
WSSiOS/WSSiOS/Source/Presentation/FeedEdit/FeedEditViewController/FeedEditViewController.swift
Outdated
Show resolved
Hide resolved
WSSiOS/WSSiOS/Source/Presentation/FeedEdit/FeedEditViewController/FeedEditViewController.swift
Show resolved
Hide resolved
Naknakk
left a comment
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.
깔꼼하네요 고생했습니다!!! 이나가 제안해준 대로 비동기&동시 작업 처리 잘 되면 좋겠습니당~!~! 다만 백그라운드에서 돌리면 피드 리스트로 돌아갈 때나 업로드 실패 시 어떻게 처리해야할지가 조금 어려운 문제 같기도 하네용 . .
| func compressImages(_ images: [UIImage], | ||
| maxImageSize: Int = MultipartConstants.maxImageSize) -> [Data] { | ||
| // 압축된 이미지 파일 배열 | ||
| var compressedDatas: [Data] = [] | ||
|
|
||
| for (index, image) in images.enumerated() { | ||
|
|
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.
W3
withThrowingTaskGroup으로 작성하면 오류 처리를 일괄적으로 할 수 있어서 좋더라구요 !! 전에 프로젝트 할 때 사용했던 코드 첨부합니당!.!
/// SwiftUI용으로 새로 나온 PhotosPicker 를 사용할 때 편하게 이미지를 업로드 할 수 있는 함수
func postPhotosPickerItem(path: String, imageName: String, item: PhotosPickerItem) async throws -> String {
guard let data = try? await item.loadTransferable(type: Data.self) else {
throw FirebaseError.encodingFailed
}
let imagePath = "\(path)/\(imageName).jpg"
return try await postData(path: imagePath, data: data)
}
/// 여러 PhotosPickerItem을 동시에 업로드 할때. post 코드는 병렬로 호출되어서 동시에 진행된다.
func postPhotosPickerItems(path: String, imageNames: [String], items: [PhotosPickerItem]) async throws -> [String] {
var results = Array(repeating: "", count: items.count)
try await withThrowingTaskGroup(of: (Int, String).self) { group in
for (index, item) in items.enumerated() {
group.addTask {
let url = try await postPhotosPickerItem(path: path, imageName: imageNames[index], item: item)
return (index, url)
}
}
for try await (index, url) in group {
results[index] = url
}
}
return results
}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.
W3
요런 방식으로 공용 컴포넌트를 만들 수 있군용 . .! 좋네요!!
| group.notify(queue: .main) { [weak self] in | ||
| self?.didSelectImages?(images) | ||
| } |
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.
W3
신기하네여 . . group에 추가된 모든 작업이 끝나면 notify를 통해 원하는 처리를 해주는 늒김 .. ? 신기하네요
⭐️Issue
🌟Motivation
해당 브랜치에서 구현된 기능 명세
-> 접근 권한을 필요로 하지 않는
PHPickerViewController를 사용하였기 때문에 해당 명세는 생략합니다.-> 접근 권한을 필요로 하지 않는
PHPickerViewController를 사용하였기 때문에 해당 명세는 생략합니다.구현안된 기능 명세
-> #571 이슈에서 진행합니다!
🌟Key Changes
🎆 이미지 파일 확장자에 따른 이미지 압축률 및 해상도 조절 함수 구현
HEIC확장자 파일의 경우 -> 높은 압축률로 작은 크기를 갖지만 JPEG 확장자로 변환 시 크기가 약 3~4배로 커지게 됩니다.이미지 파일이 들어오고 해당 파일의 확장자가
HEIC일 때 우선적으로 해상도0.5로 설정되도록 합니다.이외의 확장자 파일일 경우
기본 해상도 0.7로 설정하여 사이즈를 작게 만듭니다.
0.25MB 보다 크다면 압축 품질을 0.1씩 낮추며 이미지 크기를 측정합니다.
이후에도 조건을 만족하지 않는다면 해상도를 0.1씩 낮추면서 크기를 측정합니다.
각각의 이미지 파일마다 해당 함수를 거쳐 이미지 사이즈를 작게 만들기 때문에 피드 업로드 시 시간이 꽤나 걸리게 됩니다.
피드백할 부분이 있다면 부탁드립니다 ( _ _ )
🌟Simulation
1.mp4
1.mp4
ScreenRecording_05-25-2025.20-50-15_1.1.mp4
🌟To Reviewer
-> UI나 현재까지 구현된 기능들에서만 확인 부탁드립니다! 에러 발견이나 UX적으로 반영되면 좋겠는 부분이 있다면 언제든 환영!
🌟Reference