Skip to content

Commit

Permalink
add best image response
Browse files Browse the repository at this point in the history
  • Loading branch information
thehung111 committed Mar 7, 2023
1 parent 459a321 commit 3916f5d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
TargetAttributes = {
BDCA2E0E1DA38B7B004C2EF7 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = NKN6QECX9M;
DevelopmentTeam = 345PN8HV64;
LastSwiftMigration = 1030;
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -706,11 +706,11 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_TEAM = NKN6QECX9M;
CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_TEAM = 345PN8HV64;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.8.7;
MARKETING_VERSION = 1.9.0;
PRODUCT_BUNDLE_IDENTIFIER = com.visenze.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -722,11 +722,11 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_TEAM = NKN6QECX9M;
CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_TEAM = 345PN8HV64;
INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.8.7;
MARKETING_VERSION = 1.9.0;
PRODUCT_BUNDLE_IDENTIFIER = com.visenze.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
4 changes: 4 additions & 0 deletions ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
BD06D1361DA3BDE600EC9B38 /* ViResponseData.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD06D1351DA3BDE600EC9B38 /* ViResponseData.swift */; };
BD06D1381DA3F59A00EC9B38 /* ViRequestSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD06D1371DA3F59A00EC9B38 /* ViRequestSerialization.swift */; };
BD283ABB29B7101600912D82 /* ViBestImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD283ABA29B7101600912D82 /* ViBestImage.swift */; };
BD3A860125F22B6400BB71CF /* ViProductSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD3A860025F22B6400BB71CF /* ViProductSearch.swift */; };
BD50FD621DA8B4220035FD78 /* UIColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD50FD611DA8B4220035FD78 /* UIColorExtension.swift */; };
BD5BE9E625F5F778004995D0 /* ViProductSearchResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD5BE9E525F5F778004995D0 /* ViProductSearchResponse.swift */; };
Expand Down Expand Up @@ -83,6 +84,7 @@
/* Begin PBXFileReference section */
BD06D1351DA3BDE600EC9B38 /* ViResponseData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViResponseData.swift; sourceTree = "<group>"; };
BD06D1371DA3F59A00EC9B38 /* ViRequestSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViRequestSerialization.swift; sourceTree = "<group>"; };
BD283ABA29B7101600912D82 /* ViBestImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViBestImage.swift; sourceTree = "<group>"; };
BD3A860025F22B6400BB71CF /* ViProductSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViProductSearch.swift; sourceTree = "<group>"; };
BD50FD611DA8B4220035FD78 /* UIColorExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIColorExtension.swift; path = Helper/UIColorExtension.swift; sourceTree = "<group>"; };
BD5BE9E525F5F778004995D0 /* ViProductSearchResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViProductSearchResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -267,6 +269,7 @@
BD7020EE1E49BB99006BAE40 /* ViFacetItem.swift */,
BD815AA71FC8003800E8DA76 /* ViObjectResult.swift */,
BDD3C4D128C7A56400C0C1A4 /* ViSetInfo.swift */,
BD283ABA29B7101600912D82 /* ViBestImage.swift */,
);
path = Response;
sourceTree = "<group>";
Expand Down Expand Up @@ -442,6 +445,7 @@
BD5F70582601F1B100132A1F /* ViProductObjectResult.swift in Sources */,
BDB76A2626983C6C000C750A /* ViStrategy.swift in Sources */,
BD72A3A025FF0FA1005C8BC0 /* ViGroupResult.swift in Sources */,
BD283ABB29B7101600912D82 /* ViBestImage.swift in Sources */,
BD65405A1DA63F5200E10162 /* ViSearch.swift in Sources */,
BD7DEDAB1DA2B6C400CDF6DE /* ViColorSearchParams.swift in Sources */,
BD5BE9F225F61FE0004995D0 /* ViProduct.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ open class ViProduct {
public var alternatives: [ViProduct] = []

public var pinned: Bool? = nil

public var bestImages: [ViBestImage] = []
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ open class ViProductSearchResponse : NSObject {
item.alternatives = ViProductSearchResponse.parseProductResults(alt)
}

if let bestImages = dict["best_images"] as? [Any] {
item.bestImages = ViResponseData.parseBestImages(bestImages)
}

if let score = dict["score"] as? Double {
item.score = score
}
Expand Down
15 changes: 15 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Response/ViBestImage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ViBestImage.swift
// ViSearchSDK
//
// Created by Hung on 7/3/23.
// Copyright © 2023 Hung. All rights reserved.
//

import Foundation

open class ViBestImage: NSObject {
public var type : String? = nil
public var url : String? = nil
public var index : String? = nil
}
2 changes: 2 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Response/ViImageResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ open class ViImageResult: NSObject {

public var pinned: Bool? = nil

public var bestImages: [ViBestImage] = []

public init?(_ im_name: String) {
if im_name.isEmpty{
print("\(type(of: self)).\(#function)[line:\(#line)] - error: im_name is missing")
Expand Down
23 changes: 23 additions & 0 deletions ViSearchSDK/ViSearchSDK/Classes/Response/ViResponseData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ open class ViResponseData: NSObject {
return results
}

public static func parseBestImages(_ arr: [Any]) -> [ViBestImage]{
var results = [ViBestImage]()
for jsonItem in arr {
if let dict = jsonItem as? [String:Any] {
let type = dict["type"] as? String
let url = dict["url"] as? String
let index = dict["index"] as? String

let item = ViBestImage()
item.type = type
item.url = url
item.index = index

results.append(item)
}
}

return results
}

public static func parseProductTypes(_ arr: [Any]) -> [ViProductType]{
var results = [ViProductType]()
Expand Down Expand Up @@ -269,6 +288,10 @@ open class ViResponseData: NSObject {
item.alternatives = ViResponseData.parseResults(alternatives)
}

if let bestImages = dict["best_images"] as? [Any] {
item.bestImages = ViResponseData.parseBestImages(bestImages)
}

results.append(item)
}
else{
Expand Down

0 comments on commit 3916f5d

Please sign in to comment.