Skip to content

Commit

Permalink
[#92] Kingfisher 라이브러리 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
Taehyeon-Kim committed Aug 5, 2022
1 parent f62a2ef commit 2534695
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
17 changes: 17 additions & 0 deletions NetworkBasic/NetworkBasic.xcodeproj/project.pbxproj
Expand Up @@ -44,6 +44,7 @@
BDDF771F289A84E80096196B /* SearchResultCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDF771E289A84E80096196B /* SearchResultCollectionViewCell.swift */; };
BDDF773D289B508C0096196B /* JGProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = BDDF773C289B508C0096196B /* JGProgressHUD */; };
BDDF7751289CB3FF0096196B /* ImageSearchAPIManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDF7750289CB3FF0096196B /* ImageSearchAPIManager.swift */; };
BDDF775D289CC2F20096196B /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = BDDF775C289CC2F20096196B /* Kingfisher */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -90,6 +91,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
BDDF775D289CC2F20096196B /* Kingfisher in Frameworks */,
BD85738E28977D22007F294F /* SwiftyJSON in Frameworks */,
BDDF773D289B508C0096196B /* JGProgressHUD in Frameworks */,
BD85738B28977CF5007F294F /* Alamofire in Frameworks */,
Expand Down Expand Up @@ -305,6 +307,7 @@
BD85738A28977CF5007F294F /* Alamofire */,
BD85738D28977D22007F294F /* SwiftyJSON */,
BDDF773C289B508C0096196B /* JGProgressHUD */,
BDDF775C289CC2F20096196B /* Kingfisher */,
);
productName = NetworkBasic;
productReference = BD7915072890DDA8000A12EE /* NetworkBasic.app */;
Expand Down Expand Up @@ -338,6 +341,7 @@
BD85738928977CF5007F294F /* XCRemoteSwiftPackageReference "Alamofire" */,
BD85738C28977D22007F294F /* XCRemoteSwiftPackageReference "SwiftyJSON" */,
BDDF773B289B508C0096196B /* XCRemoteSwiftPackageReference "JGProgressHUD" */,
BDDF775B289CC2F20096196B /* XCRemoteSwiftPackageReference "Kingfisher" */,
);
productRefGroup = BD7915082890DDA8000A12EE /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -640,6 +644,14 @@
minimumVersion = 2.0.0;
};
};
BDDF775B289CC2F20096196B /* XCRemoteSwiftPackageReference "Kingfisher" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/onevcat/Kingfisher.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 7.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -658,6 +670,11 @@
package = BDDF773B289B508C0096196B /* XCRemoteSwiftPackageReference "JGProgressHUD" */;
productName = JGProgressHUD;
};
BDDF775C289CC2F20096196B /* Kingfisher */ = {
isa = XCSwiftPackageProductDependency;
package = BDDF775B289CC2F20096196B /* XCRemoteSwiftPackageReference "Kingfisher" */;
productName = Kingfisher;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = BD7914FF2890DDA8000A12EE /* Project object */;
Expand Down
Expand Up @@ -18,6 +18,15 @@
"version" : "2.2.0"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher.git",
"state" : {
"revision" : "2231f92b5af71c78ad2c1450e583bf4a8713b951",
"version" : "7.3.1"
}
},
{
"identity" : "swiftyjson",
"kind" : "remoteSourceControl",
Expand Down
Expand Up @@ -38,7 +38,7 @@ final class ImageSearchAPIManager {
print("JSON: \(json)")

let totalCount = json["total"].intValue
let list = json["item"].arrayValue.map { $0["thumbnail"].stringValue }
let list = json["items"].arrayValue.map { $0["thumbnail"].stringValue }

completionHandler(totalCount, list)

Expand Down
Expand Up @@ -31,6 +31,8 @@ class ImageSearchViewController: UIViewController {
self.totalCount = totalCount
self.list.append(contentsOf: list)

print(list)

DispatchQueue.main.async {
self.collectionView.reloadData()
}
Expand All @@ -42,10 +44,9 @@ extension ImageSearchViewController: UISearchBarDelegate {

// 검색 버튼 클릭 시 실행. (키보드 Return키에 디폴트 구현)
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {

list.removeAll()
if let text = searchBar.text {
// 검색 결과가 계속 바뀌기 때문에, 그럴 때마다 초기화 해줄 필요가 있음
list.removeAll()
startPage = 1
collectionView.scrollsToTop = true
fetchImage(query: text)
Expand Down Expand Up @@ -88,6 +89,7 @@ extension ImageSearchViewController: UICollectionViewDelegate, UICollectionViewD
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SearchResultCollectionViewCell.reuseidentifier, for: indexPath) as? SearchResultCollectionViewCell else {
return UICollectionViewCell()
}
print("cell")
cell.configureCell(withImageString: list[indexPath.row])
return cell
}
Expand Down
Expand Up @@ -7,6 +7,8 @@

import UIKit

import Kingfisher

final class SearchResultCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var ImageView: UIImageView! {
didSet {
Expand All @@ -15,12 +17,8 @@ final class SearchResultCollectionViewCell: UICollectionViewCell {
}

func configureCell(withImageString imageString: String?) {
guard let imageURLString = imageString else { return }
let imageURL = URL(string: imageURLString)
if let imageData = try? Data(contentsOf: imageURL!) {
self.ImageView.image = UIImage(data: imageData)
} else {
self.ImageView.backgroundColor = .black
if let url = URL(string: imageString!) {
ImageView.kf.setImage(with: url)
}
}
}

0 comments on commit 2534695

Please sign in to comment.