CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate CDYelpFusionKit into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'CDYelpFusionKit', '3.2.0'
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate CDYelpFusionKit into your Xcode project using Carthage, specify it in your Cartfile:
github "chrisdhaan/CDYelpFusionKit" == 3.2.0
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding CDYelpFusionKit as a dependency is as easy as adding it to the dependencies value of your Package.swift.
Open the new CDYelpFusionKit folder, and drag the CDYelpFusionKit.xcodeproj into the Project Navigator of your application’s Xcode project.
It should appear nested underneath your application’s blue project icon. Whether it is above or below all the other Xcode groups does not matter.
Select the CDYelpFusionKit.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.
Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the “Targets” heading in the sidebar.
In the tab bar at the top of that window, open the “General” panel.
Click on the + button under the “Embedded Binaries” section.
You will see two different CDYelpFusionKit.xcodeproj folders each with two different versions of the CDYelpFusionKit.framework nested inside a Products folder.
It does not matter which Products folder you choose from, but it does matter whether you choose the top or bottom CDYelpFusionKit.framework.
Select the top CDYelpFusionKit.framework for iOS and the bottom one for macOS.
You can verify which one you selected by inspecting the build log for your project. The build target for CDYelpFusionKit will be listed as either CDYelpFusionKit iOS, CDYelpFusionKit macOS, CDYelpFusionKit tvOS or CDYelpFusionKit watchOS.
And that’s it!
The CDYelpFusionKit.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.
Contributing
Before contributing to CDYelpFusionKit, please read the instructions detailed in our contribution guide.
Usage
Initialization
let yelpAPIClient = CDYelpAPIClient(apiKey: "YOUR_API_KEY")
Once you’ve created a CDYelpAPIClient object you can use it to query the Yelp Fusion API using any of the following methods.
Parameters with // Optional can take nil as a value.
Parameters with // Required will throw an exception when passing nil as a value.
The search endpoint has a categories parameter which allows for query results to be returned based off one thousand four hundred and sixty-one types of categories. The full list of categories can be found in CDYelpEnums.swift. The following lines of code show an example of a category that can be passed into the categories parameter.
CDYelpCategoryAlias.activeLife
The search endpoint has a locale parameter which allows for query results to be returned based off forty-two types of language and country codes. The following lines of code show which locales can be passed into the locale parameter.
The search endpoint has a sortBy parameter which allows for query results to be filtered based off four types of criteria. The following lines of code show which sort types can be passed into the sortBy parameter.
The search endpoint has a price parameter which allows for query results to be filtered based off four types of criteria. The following lines of code show which price tiers can be passed into the priceTiers parameter.
The search endpoint has an attributes parameter which allows for query results to be filtered based off five types of criteria. The following lines of code show which attributes can be passed into the attributes parameter.
The transactions search endpoint has a type parameter which allows for query results to be filtered based off one type of criteria. The following lines of code show which transaction types can be passed into the byType parameter.
CDYelpTransactionType.foodDelivery
The following lines of code show an example query to the transactions search endpoint.
yelpAPIClient.searchTransactions(byType: .foodDelivery,
location: "San Francisco",
latitude: nil,
longitude: nil) { (response) in
if let response = response,
let businesses = response.businesses,
businesses.count > 0 {
print(businesses)
}
}
The following lines of code show an example query to the business endpoint.
yelpAPIClient.fetchBusiness(forId: "north-india-restaurant-san-francisco"
locale: nil) { (business) in
if let response = response,
let business = response.business {
print(business)
}
}
public func searchBusinesses(name: String!, // Required - Max length = 64
addressOne: String?, // Optional - Max length = 64
addressTwo: String?, // Optional - Max length = 64
addressThree: String?, // Optional - Max length = 64
city: String!, // Required - Max length = 64
state: String!, // Required - Max length = 3
country: String!, // Required - Max length = 2
latitude: Double?, // Optional - Min = -90, Max = +90
longitude: Double?, // Optional - Min = -180, Max = +180
phone: String?, // Optional - Max length = 32
zipCode: String?, // Optional
yelpBusinessId: String?, // Optional
limit: Int?, // Optional - Min = 1, Default = 3, Max = 10
matchThresholdType: CDYelpBusinessMatchThresholdType, // Required
completion: @escaping (CDYelpSearchResponse.BusinessMatch?) -> Void)
The business match endpoint has a matchThresholdType parameter which allows for query results to be filtered based off three types of criteria. The following lines of code show which business match threshold types can be passed into the matchThresholdType parameter.
The reviews endpoint has a locale parameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using the locale parameter.
The following lines of code show an example query to the reviews endpoint.
yelpAPIClient.fetchReviews(forBusinessId: "north-india-restaurant-san-francisco",
locale: nil) { (reviews) in
if let response = response,
let reviews = response.reviews,
reviews.count > 0 {
print(reviews)
}
}
The autocomplete endpoint has a locale parameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using the locale parameter.
The following lines of code show an example query to the autocomplete endpoint.
yelpAPIClient.autocompleteBusinesses(byText: "Pizza Delivery",
latitude: 37.786572,
longitude: -122.415192,
locale: nil) { (response) in
if let response = response,
let businesses = response.businesses,
businesses.count > 0 {
print(businesses)
}
}
The event lookup endpoint has a locale parameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using the locale parameter.
The following lines of code show an example query to the event lookup endpoint.
yelpAPIClient.fetchEvent(forId: "san-francisco-yelp-celebrates-pride-month-2021",
locale: nil) { (event) in
if let response = response,
event = response.event {
print(event)
}
}
The event search endpoint has a locale parameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using the locale parameter.
The event search endpoint has a sortBy parameter which allows for query results to be filtered based off two types of criteria. The following lines of code show which sort types can be passed into the sortBy parameter.
The event search endpoint has a sortOn parameter which allows for query results to be filtered based off two types of criteria. The following lines of code show which sort types can be passed into the sortBy parameter.
The event search endpoint has a categories parameter which allows for query results to be returned based off thirteen types of categories. The following lines of code show which category types can be passed into the categories parameter.
The featured event endpoint has a locale parameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using the locale parameter.
The following lines of code show an example query to the featured event endpoint.
yelpAPIClient.fetchFeaturedEvent(forLocale: nil,
location: nil,
latitude: 37.786572,
longitude: -122.415192) { (event) in
if let response = response,
event = response.event {
print(event)
}
}
The all categories endpoint has a locale parameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using the locale parameter.
The following lines of code show an example query to the featured event endpoint.
yelpAPIClient.fetchCategories(forLocale: nil) { (response) in
if let response = response,
let categories = response.categories {
print(categories)
}
}
The category details endpoint has an alias parameter which allows for query results to be returned based off one thousand four hundred and sixty-one types of categories. The full list of categories can be found in CDYelpEnums.swift. The following lines of code show an example of a category that can be passed into the alias parameter.
CDYelpCategoryAlias.activeLife
The category details endpoint has a locale parameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using the locale parameter.
The following lines of code show an example query to the featured event endpoint.
yelpAPIClient.fetchCategory(forAlias: .fastFood,
andLocale: nil) { (response) in
if let response = response,
let category = response.category {
print(category)
}
}
The Yelp iPhone application registers URL schemes that can be used to open the Yelp application, perform searches, view business information, or check-in.
static func yelpDeepLink() -> URL?
The following lines of code show an example of how to check if the Yelp application is installed and then open it.
if let url = URL.yelpDeepLink(),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url,
options: [:],
completionHandler: nil)
}
The search deep link has a category parameter which allows for query results to be returned based off one thousand four hundred and sixty-one types of categories. Refer to the search endpoint for information regarding using the category parameter.
The following lines of code show an example query to the search deep link.
if let url = URL.yelpSearchDeepLink(withTerm: "burrito",
category: .food,
location: "San Francisco, CA"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url,
options: [:],
completionHandler: nil)
}
The search deep link has a category parameter which allows for query results to be returned based off one thousand four hundred and sixty-one types of categories. Refer to the search endpoint for information regarding using the category parameter.
The following lines of code show an example query to the search web link.
if let url = URL.yelpSearchWebLink(withTerm: "burrito",
category: .food,
location: "San Francisco, CA"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url,
options: [:],
completionHandler: nil)
}
class func yelpLogo() -> UIImage?
class func yelpLogoOutline() -> UIImage?
class func yelpBurstLogoRed() -> UIImage?
class func yelpBurstLogoWhite() -> UIImage?
The following lines of code show examples of how to use the brand logo and the brand burst logo.
class func yelpStars(numberOfStars: CDYelpStars!,
forSize size: CDYelpStarsSize!) -> UIImage?
The stars image has a numberOfStars parameter which defines the number of filled stars in the returned image. The following lines of code show which number of stars can be passed into the numberOfStars parameter.
The stars image has a forSize parameter which defines the size of the returned image. The following lines of code show which sizes can be passed into the forSize parameter.
This Swift wrapper covers all possible network endpoints and responses for the Yelp Fusion API.
For a demonstration of the capabilities of CDYelpFusionKit; run the iOS Example project after cloning the repo.
Features
Requirements
Dependencies
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate CDYelpFusionKit into your Xcode project using CocoaPods, specify it in your
Podfile:Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate CDYelpFusionKit into your Xcode project using Carthage, specify it in your
Cartfile:Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the
swiftcompiler.Once you have your Swift package set up, adding CDYelpFusionKit as a dependency is as easy as adding it to the
dependenciesvalue of yourPackage.swift.Git Submodule
If you prefer not to use any of the aforementioned dependency managers, you can integrate CDYelpFusionKit into your project manually.
cdinto your top-level project directory, and run the following command “if” your project is not initialized as a git repository:Open the new
CDYelpFusionKitfolder, and drag theCDYelpFusionKit.xcodeprojinto the Project Navigator of your application’s Xcode project.Select the
CDYelpFusionKit.xcodeprojin the Project Navigator and verify the deployment target matches that of your application target.Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the “Targets” heading in the sidebar.
In the tab bar at the top of that window, open the “General” panel.
Click on the
+button under the “Embedded Binaries” section.You will see two different
CDYelpFusionKit.xcodeprojfolders each with two different versions of theCDYelpFusionKit.frameworknested inside aProductsfolder.Select the top
CDYelpFusionKit.frameworkfor iOS and the bottom one for macOS.And that’s it!
Contributing
Before contributing to CDYelpFusionKit, please read the instructions detailed in our contribution guide.
Usage
Initialization
Once you’ve created a CDYelpAPIClient object you can use it to query the Yelp Fusion API using any of the following methods.
// Optionalcan take nil as a value.// Requiredwill throw an exception when passing nil as a value.Search Endpoint
The search endpoint has a
categoriesparameter which allows for query results to be returned based off one thousand four hundred and sixty-one types of categories. The full list of categories can be found inCDYelpEnums.swift. The following lines of code show an example of a category that can be passed into thecategoriesparameter.The search endpoint has a
localeparameter which allows for query results to be returned based off forty-two types of language and country codes. The following lines of code show which locales can be passed into thelocaleparameter.The search endpoint has a
sortByparameter which allows for query results to be filtered based off four types of criteria. The following lines of code show which sort types can be passed into thesortByparameter.The search endpoint has a
priceparameter which allows for query results to be filtered based off four types of criteria. The following lines of code show which price tiers can be passed into thepriceTiersparameter.The search endpoint has an
attributesparameter which allows for query results to be filtered based off five types of criteria. The following lines of code show which attributes can be passed into theattributesparameter.The following lines of code show an example query to the search endpoint.
Phone Search Endpoint
The following lines of code show an example query to the phone search endpoint.
Transaction Search Endpoint
The transactions search endpoint has a
typeparameter which allows for query results to be filtered based off one type of criteria. The following lines of code show which transaction types can be passed into thebyTypeparameter.The following lines of code show an example query to the transactions search endpoint.
Business Endpoint
The following lines of code show an example query to the business endpoint.
Business Match Endpoint
The business match endpoint has a
matchThresholdTypeparameter which allows for query results to be filtered based off three types of criteria. The following lines of code show which business match threshold types can be passed into thematchThresholdTypeparameter.The following lines of code show an example query to the business match endpoint.
Reviews Endpoint
The reviews endpoint has a
localeparameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using thelocaleparameter.The following lines of code show an example query to the reviews endpoint.
Autocomplete Endpoint
The autocomplete endpoint has a
localeparameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using thelocaleparameter.The following lines of code show an example query to the autocomplete endpoint.
Event Lookup Endpoint
The event lookup endpoint has a
localeparameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using thelocaleparameter.The following lines of code show an example query to the event lookup endpoint.
Event Search Endpoint
The event search endpoint has a
localeparameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using thelocaleparameter.The event search endpoint has a
sortByparameter which allows for query results to be filtered based off two types of criteria. The following lines of code show which sort types can be passed into thesortByparameter.The event search endpoint has a
sortOnparameter which allows for query results to be filtered based off two types of criteria. The following lines of code show which sort types can be passed into thesortByparameter.The event search endpoint has a
categoriesparameter which allows for query results to be returned based off thirteen types of categories. The following lines of code show which category types can be passed into thecategoriesparameter.The following lines of code show an example query to the event search endpoint.
Featured Event Endpoint
The featured event endpoint has a
localeparameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using thelocaleparameter.The following lines of code show an example query to the featured event endpoint.
All Categories Endpoint
The all categories endpoint has a
localeparameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using thelocaleparameter.The following lines of code show an example query to the featured event endpoint.
Category Details Endpoint
The category details endpoint has an
aliasparameter which allows for query results to be returned based off one thousand four hundred and sixty-one types of categories. The full list of categories can be found inCDYelpEnums.swift. The following lines of code show an example of a category that can be passed into thealiasparameter.The category details endpoint has a
localeparameter which allows for query results to be returned based off forty-two types of language and country codes. Refer to the search endpoint for information regarding using thelocaleparameter.The following lines of code show an example query to the featured event endpoint.
Deep Linking
The Yelp iPhone application registers URL schemes that can be used to open the Yelp application, perform searches, view business information, or check-in.
The following lines of code show an example of how to check if the Yelp application is installed and then open it.
Search
The search deep link has a
categoryparameter which allows for query results to be returned based off one thousand four hundred and sixty-one types of categories. Refer to the search endpoint for information regarding using thecategoryparameter.The following lines of code show an example query to the search deep link.
Business
The following lines of code show an example query to the business deep link.
Check In Nearby
The following lines of code show an example query to the check in nearby deep link.
Check-Ins
The following lines of code show an example query to the check-ins deep link.
Check-In Rankings
The following lines of code show an example query to the check-in rankings deep link.
Web Linking
The Yelp website registers URL schemes that can be used to open the Yelp website, perform searches or view business information.
The following lines of code show an example of how to open the Yelp website.
Search
The search deep link has a
categoryparameter which allows for query results to be returned based off one thousand four hundred and sixty-one types of categories. Refer to the search endpoint for information regarding using thecategoryparameter.The following lines of code show an example query to the search web link.
Business
The following lines of code show an example query to the business web link.
Brand Assets
The Yelp brand guidelines exist to achieve consistency and make sure the branded elements of Yelp are used correctly across every application.
Color
The following lines of code show an example of how to use the brand color.
Logo
The following lines of code show examples of how to use the brand logo and the brand burst logo.
Stars
The stars image has a
numberOfStarsparameter which defines the number of filled stars in the returned image. The following lines of code show which number of stars can be passed into thenumberOfStarsparameter.The stars image has a
forSizeparameter which defines the size of the returned image. The following lines of code show which sizes can be passed into theforSizeparameter.The following lines of code show an example of how to use the stars image.
Author
Christopher de Haan, contact@christopherdehaan.me
Resources
Visit the Yelp Developers portal for additional resources regarding the Yelp API.
License
CDYelpFusionKit is available under the MIT license. See the LICENSE file for more info.