diff --git a/instantsearch-ios/getting-started/README.md b/instantsearch-ios/getting-started/README.md new file mode 100644 index 000000000..d1c88cc5b --- /dev/null +++ b/instantsearch-ios/getting-started/README.md @@ -0,0 +1,16 @@ +# InstantSearch iOS getting started sample + +This sample shows how to get started on building your search experience by easily adding common InstantSearch components. + +## Get started + +Clone the getting started sample: + +```sh +curl https://codeload.github.com/algolia/doc-code-samples/tar.gz/master | tar -xz --strip=2 doc-code-samples-master/instantsearch-ios/getting-started +``` + +Open `SearchApp.xcodeproj` in Xcode, and run the app on a simulator or device. + +## Additional resources +Learn more about InstantSearch iOS [widgets](https://www.algolia.com/doc/guides/building-search-ui/widgets/showcase/ios/) in the Algolia documentation. diff --git a/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.pbxproj b/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.pbxproj new file mode 100644 index 000000000..d2491342c --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.pbxproj @@ -0,0 +1,353 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 77; + objects = { + +/* Begin PBXBuildFile section */ + 25A9E5EB2E3CBC61003F2C5E /* InstantSearchSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 25A9E5EA2E3CBC61003F2C5E /* InstantSearchSwiftUI */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 25A9E5DB2E3CBBFB003F2C5E /* SearchApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SearchApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFileSystemSynchronizedRootGroup section */ + 25A9E5DD2E3CBBFB003F2C5E /* SearchApp */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = SearchApp; + sourceTree = ""; + }; +/* End PBXFileSystemSynchronizedRootGroup section */ + +/* Begin PBXFrameworksBuildPhase section */ + 25A9E5D82E3CBBFB003F2C5E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 25A9E5EB2E3CBC61003F2C5E /* InstantSearchSwiftUI in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 25A9E5D22E3CBBFB003F2C5E = { + isa = PBXGroup; + children = ( + 25A9E5DD2E3CBBFB003F2C5E /* SearchApp */, + 25A9E5DC2E3CBBFB003F2C5E /* Products */, + ); + sourceTree = ""; + }; + 25A9E5DC2E3CBBFB003F2C5E /* Products */ = { + isa = PBXGroup; + children = ( + 25A9E5DB2E3CBBFB003F2C5E /* SearchApp.app */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 25A9E5DA2E3CBBFB003F2C5E /* SearchApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = 25A9E5E62E3CBBFC003F2C5E /* Build configuration list for PBXNativeTarget "SearchApp" */; + buildPhases = ( + 25A9E5D72E3CBBFB003F2C5E /* Sources */, + 25A9E5D82E3CBBFB003F2C5E /* Frameworks */, + 25A9E5D92E3CBBFB003F2C5E /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + fileSystemSynchronizedGroups = ( + 25A9E5DD2E3CBBFB003F2C5E /* SearchApp */, + ); + name = SearchApp; + packageProductDependencies = ( + 25A9E5EA2E3CBC61003F2C5E /* InstantSearchSwiftUI */, + ); + productName = SearchApp; + productReference = 25A9E5DB2E3CBBFB003F2C5E /* SearchApp.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 25A9E5D32E3CBBFB003F2C5E /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1640; + LastUpgradeCheck = 1640; + TargetAttributes = { + 25A9E5DA2E3CBBFB003F2C5E = { + CreatedOnToolsVersion = 16.4; + }; + }; + }; + buildConfigurationList = 25A9E5D62E3CBBFB003F2C5E /* Build configuration list for PBXProject "SearchApp" */; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 25A9E5D22E3CBBFB003F2C5E; + minimizedProjectReferenceProxies = 1; + packageReferences = ( + 25A9E5E92E3CBC61003F2C5E /* XCRemoteSwiftPackageReference "instantsearch-ios" */, + ); + preferredProjectObjectVersion = 77; + productRefGroup = 25A9E5DC2E3CBBFB003F2C5E /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 25A9E5DA2E3CBBFB003F2C5E /* SearchApp */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 25A9E5D92E3CBBFB003F2C5E /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 25A9E5D72E3CBBFB003F2C5E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 25A9E5E42E3CBBFC003F2C5E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.5; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 25A9E5E52E3CBBFC003F2C5E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.5; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 25A9E5E72E3CBBFC003F2C5E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.SearchApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 25A9E5E82E3CBBFC003F2C5E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.SearchApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 25A9E5D62E3CBBFB003F2C5E /* Build configuration list for PBXProject "SearchApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 25A9E5E42E3CBBFC003F2C5E /* Debug */, + 25A9E5E52E3CBBFC003F2C5E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 25A9E5E62E3CBBFC003F2C5E /* Build configuration list for PBXNativeTarget "SearchApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 25A9E5E72E3CBBFC003F2C5E /* Debug */, + 25A9E5E82E3CBBFC003F2C5E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 25A9E5E92E3CBC61003F2C5E /* XCRemoteSwiftPackageReference "instantsearch-ios" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/algolia/instantsearch-ios"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 7.27.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 25A9E5EA2E3CBC61003F2C5E /* InstantSearchSwiftUI */ = { + isa = XCSwiftPackageProductDependency; + package = 25A9E5E92E3CBC61003F2C5E /* XCRemoteSwiftPackageReference "instantsearch-ios" */; + productName = InstantSearchSwiftUI; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 25A9E5D32E3CBBFB003F2C5E /* Project object */; +} diff --git a/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 000000000..8158fc8ba --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,51 @@ +{ + "originHash" : "ea8f27e1a2bd7273484d2c19c8b43a41b1dcca14ac8ee25619ca2c95f332ef90", + "pins" : [ + { + "identity" : "algoliasearch-client-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/algolia/algoliasearch-client-swift", + "state" : { + "revision" : "4322ab2dc8cdb7acb6d06a019fd56f84dc998f25", + "version" : "8.21.0" + } + }, + { + "identity" : "instantsearch-ios", + "kind" : "remoteSourceControl", + "location" : "https://github.com/algolia/instantsearch-ios", + "state" : { + "revision" : "5f94daaff8e0e75f4793ecd14cc45efae5f50a24", + "version" : "7.27.0" + } + }, + { + "identity" : "instantsearch-telemetry-native", + "kind" : "remoteSourceControl", + "location" : "https://github.com/algolia/instantsearch-telemetry-native", + "state" : { + "revision" : "d9861ceb2fe25899a31672fb7c648ae8036d3221", + "version" : "0.1.3" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log", + "state" : { + "revision" : "ce592ae52f982c847a4efc0dd881cc9eb32d29f2", + "version" : "1.6.4" + } + }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "102a647b573f60f73afdce5613a51d71349fe507", + "version" : "1.30.0" + } + } + ], + "version" : 3 +} diff --git a/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/xcuserdata/dhaya.benmessaoud.xcuserdatad/UserInterfaceState.xcuserstate b/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/xcuserdata/dhaya.benmessaoud.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 000000000..80d268bed Binary files /dev/null and b/instantsearch-ios/getting-started/SearchApp.xcodeproj/project.xcworkspace/xcuserdata/dhaya.benmessaoud.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/instantsearch-ios/getting-started/SearchApp.xcodeproj/xcuserdata/dhaya.benmessaoud.xcuserdatad/xcschemes/xcschememanagement.plist b/instantsearch-ios/getting-started/SearchApp.xcodeproj/xcuserdata/dhaya.benmessaoud.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 000000000..af1bfce90 --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp.xcodeproj/xcuserdata/dhaya.benmessaoud.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + SearchApp.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/AccentColor.colorset/Contents.json b/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 000000000..eb8789700 --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..230588010 --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,35 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "tinted" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/Contents.json b/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/instantsearch-ios/getting-started/SearchApp/ContentView.swift b/instantsearch-ios/getting-started/SearchApp/ContentView.swift new file mode 100644 index 000000000..e424adfb3 --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp/ContentView.swift @@ -0,0 +1,139 @@ +// +// ContentView.swift +// SearchApp +// +// Created by Algolia on 01/08/2025. +// + +import InstantSearchCore +import InstantSearchSwiftUI +import SwiftUI + +struct Product: Codable { + let name: String +} + +class AlgoliaController { + let searcher: HitsSearcher + + let searchBoxInteractor: SearchBoxInteractor + let searchBoxController: SearchBoxObservableController + + let hitsInteractor: HitsInteractor + let hitsController: HitsObservableController + + let statsInteractor: StatsInteractor + let statsController: StatsTextObservableController + + let filterState: FilterState + + let facetListInteractor: FacetListInteractor + let facetListController: FacetListObservableController + + init() { + self.searcher = HitsSearcher(appID: "latency", + apiKey: "1f6fd3a6fb973cb08419fe7d288fa4db", + indexName: "bestbuy") + self.searchBoxInteractor = .init() + self.searchBoxController = .init() + self.hitsInteractor = .init() + self.hitsController = .init() + self.statsInteractor = .init() + self.statsController = .init() + self.filterState = .init() + self.facetListInteractor = .init() + self.facetListController = .init() + + setupConnections() + } + + func setupConnections() { + searchBoxInteractor.connectSearcher(searcher) + searchBoxInteractor.connectController(searchBoxController) + hitsInteractor.connectSearcher(searcher) + hitsInteractor.connectController(hitsController) + statsInteractor.connectSearcher(searcher) + statsInteractor.connectController(statsController) + searcher.connectFilterState(filterState) + facetListInteractor.connectSearcher(searcher, with: "manufacturer") + facetListInteractor.connectFilterState(filterState, with: "manufacturer", operator: .or) + facetListInteractor.connectController(facetListController, with: FacetListPresenter(sortBy: [.isRefined, .count(order: .descending)])) + } +} + +struct ContentView: View { + @ObservedObject var searchBoxController: SearchBoxObservableController + @ObservedObject var hitsController: HitsObservableController + @ObservedObject var statsController: StatsTextObservableController + @ObservedObject var facetListController: FacetListObservableController + + @State private var isEditing = false + @State private var isPresentingFacets = false + + var body: some View { + VStack(spacing: 7) { + Text(statsController.stats) + .fontWeight(.medium) + HitsList(hitsController) { hit, _ in + VStack(alignment: .leading, spacing: 10) { + Text(hit?.name ?? "") + .padding(.all, 10) + Divider() + } + } noResults: { + Text("No Results") + .frame(maxWidth: .infinity, maxHeight: .infinity) + } + } + .padding(.horizontal) + .padding(.top, 10) + .searchable(text: $searchBoxController.query) + .navigationBarTitle("Algolia & SwiftUI") + .navigationBarItems(trailing: facetsButton()) + .sheet(isPresented: $isPresentingFacets, content: facets) + } + + @ViewBuilder + private func facets() -> some View { + NavigationView { + ScrollView { + FacetList(facetListController) { facet, isSelected in + VStack { + FacetRow(facet: facet, isSelected: isSelected) + .padding() + Divider() + } + } noResults: { + Text("No facet found") + .frame(maxWidth: .infinity, maxHeight: .infinity) + } + } + .navigationBarTitle("Brand") + } + } + + private func facetsButton() -> some View { + Button(action: { + isPresentingFacets.toggle() + }, label: { + Image(systemName: "line.horizontal.3.decrease.circle") + .font(.title) + }) + } + + +} + +struct ContentView_Previews: PreviewProvider { + static let algoliaController = AlgoliaController() + static var previews: some View { + NavigationView { + ContentView(searchBoxController: algoliaController.searchBoxController, + hitsController: algoliaController.hitsController, + statsController: algoliaController.statsController, + facetListController: algoliaController.facetListController) + }.onAppear { + algoliaController.searcher.search() + } + } +} diff --git a/instantsearch-ios/getting-started/SearchApp/SearchAppApp.swift b/instantsearch-ios/getting-started/SearchApp/SearchAppApp.swift new file mode 100644 index 000000000..c8b2c2e0e --- /dev/null +++ b/instantsearch-ios/getting-started/SearchApp/SearchAppApp.swift @@ -0,0 +1,26 @@ +// +// SearchAppApp.swift +// SearchApp +// +// Created by Algolia on 01/08/2025. +// + +import SwiftUI + +@main +struct SearchAppApp: App { + private var algoliaController = AlgoliaController() + var body: some Scene { + WindowGroup { + NavigationStack { + ContentView(searchBoxController: algoliaController.searchBoxController, + hitsController: algoliaController.hitsController, + statsController: algoliaController.statsController, + facetListController: algoliaController.facetListController) + } + .onAppear { + algoliaController.searcher.search() + } + } + } +}