Barikoi Auto-complete Places SDK is a package that provides extensive information about places around Bangladesh in both English and Bangla. Let me explain the Barikoi Places Auto-complete SDK which I've developed for work purposes, and you can use it with both Swift UIKit and SwiftUI. [Currently minimum iOS version 14 needed]
Here's how you can integrate it into your Swift UIKit project:
- Add the Barikoi Places auto-complete Package to your iOS project and create a UI element like a button to connect with the Barikoi View Controller.
- Get an API key from the Barikoi Website and set it to the AppDelegate.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BarikoiPlacesClient.myApiKey("YourApiKey")
return true
}
- Create an instance of the Barikoi View Controller, set the parent view controller as the delegate and present it using [self presentViewController...].
let vc = BarikoiViewController()
vc.delegate = self
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true)
- Implement the Barikoi Autocomplete Delegate protocol in the parent view controller and handle the user's selection in the places(_ :) delegate method. And you will receive the response in the BarikoiModel model.
class YourViewController: BarikoiAutocompleteDelegate {
func places(_ data: BarikoiPlaces.Place) {
print(data)
}
}
For SwiftUI:
Adding a full-screen control to your SwiftUI app is straightforward. Here's how you can do it:
- Define a @State variable to control the presentation of the Barikoi Auto-Complete View. Present the view using [.sheet…].
struct SwiftUIView: View {
@State var isPresent = false
var body: some View {
VStack {
Button(action: {
isPresent.toggle()
}, label: {
Text("Present")
})
}
.sheet(isPresented: $isPresent) {
BarikoiAutoCompleteViewSiwftUI(apiKey: "YourApiKey", dismissAction: {
isPresent = false
}, didTapPlace: { place in
print("Selected Places: \(place)")
})
}
}
}
[For any assistance or suggestions, feel free to send me a message on LinkedIn]