Giter Site home page Giter Site logo

Comments (6)

Settpark avatar Settpark commented on September 1, 2024

첫번째 해결 사항:
URLSession.shared.datatask 부분에 resume()을 기입하지 않음. 기입 후 테스트 -> 여전히 이미지 표시 되지 않음

from rxsidedishes.

Settpark avatar Settpark commented on September 1, 2024

두번째 해결 사항:

  • 함수 fetchAndCacheImage 디자인 자체가 잘못 됨
  • 그리고 캐시를 다시 service영역까지 요청하면 안되고 repo영역에서 저장된 캐시가 없어 해결할 수 없을 때 아래의 코드를 실행해야 한다.
if let url = URL(string: url) {
        URLSession.shared.dataTask(with: url) { [weak self] data, response, error in
            if let _ = error {
                resultImage = UIImage()
            }
            if let data = data, let image = UIImage(data: data) {
                self?.cacheManager.setObject(image, forKey: cacheKey)
                resultImage = image
            }
        }.resume()

from rxsidedishes.

Settpark avatar Settpark commented on September 1, 2024

세번째 해결 사항:

api요청으로 부터 받는 코드는 모두 비동기이다.
따라서 우선은 전부 escaping을 통하여 처리하였다.

    func banchanList(usecase: BanchanUsecase) -> Observable<[Banchan]> { //여기서 usecase만 전달 //apiService에선 주입받은 apimaker를 바탕으로 동작하도록
        apiService.fetchDataWithRx(usecase: usecase)
            .map {$0.body}
            .subscribe(onNext: { [weak self] data in
                var banchans = Array<Banchan>(repeating: Banchan.empty, count: data.count)
                for i in 0..<data.count {
                    let temp = data[i]
                    self?.imageManager.getCachedImage(url: data[i].image, onComplete: { result in
                        switch result {
                        case .success(let image):
                            banchans[i] = Banchan.init(hash: temp.detailHash,
                                                       image: image,
                                                       alt: temp.alt,
                                                       deliveryType: temp.deliveryType,
                                                       title: temp.title,
                                                       description: temp.description,
                                                       nPrice: temp.nPrice,
                                                       sPrice: temp.sPrice,
                                                       badge: temp.badge)
                            self?.eventer.onNext(banchans)
                        case .failure(let err):
                            print(err)
                        }
                    })
                }
            }).disposed(by: disposeBag)
        return eventer
    }

반찬 객체를 매번 생성해서 하다보니 코드가 지나치게 길어진다. 허나 DTO와 entitiy의 내부 모델이 다르기 때문에 banchan을 생성 안할 수가 없는데... 다른 방법이 있나 고민해봐야겠다.

from rxsidedishes.

Settpark avatar Settpark commented on September 1, 2024

다섯 번째 해결 사항:

  • 이미지의 fetch 역시 비동기로 처리하였다.
func getfetchedImage(url: String, onComplete: @escaping (Result<UIImage, Error>) -> Void) {
    if let url = URL(string: url) {
        URLSession.shared.dataTask(with: url) { data, response, error in
            if let err = error {
                onComplete(.failure(err))
            }
            DispatchQueue.main.async {
                if let data = data, let image = UIImage(data: data) {
                    onComplete(.success(image))
                }
            }
        }.resume()
    }
}

from rxsidedishes.

Settpark avatar Settpark commented on September 1, 2024
  • 현재 이미지는 불러와지나 메모리 캐시로 처리했기 때문에 앱을 재시작하면 의미가 없다.
  • 현재 내 앱에는 이미지를 한번 다운로드하면 그 다음 부터 다시 이미지를 부를 일이 없다.
  • Disk cache로 진행해야 더 의미 있는 코드가 될듯.

from rxsidedishes.

Settpark avatar Settpark commented on September 1, 2024

preparereuse에서 imageView.image = nil 하는 작업을 빼먹어서 리로드 안되는 줄 알았는데 그냥 안됨.
아마 그냥 비동기로 처리하고 Rx로 구독하고 있지 않아서가 아닐까..?

from rxsidedishes.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.