How to build a Book Finder App with Xcode and AI

Team Alex · April 6, 2025

Tutorial

Estimated completion time: 3 min read

How to Build a Book Finder App with Xcode and AI

Overview

In this tutorial, we'll build a powerful yet simple Book Finder app for iOS using Xcode, Swift, SwiftUI, and the Google Books API. We’ll also use Alex, an AI tool that helps speed up iOS development by generating code and fixing issues automatically.

You'll learn how to:

  • Set up a SwiftUI project in Xcode
  • Search for books using the Google Books API
  • Display results in a clean list and detailed view
  • Persist previous searches
  • Use Alex to write and debug SwiftUI code

Prerequisites:


1. Project Setup & Planning

Create a new Xcode project:

  • Choose iOS > App
  • Product Name: BookFinder
  • Interface: SwiftUI
  • Language: Swift

Plan your views:

  • SearchView: for entering a query
  • BookListView: for displaying search results
  • BookDetailView: for showing detailed book info

Let Alex know:
"Create a SwiftUI view with a text field for search and a list below to show books."


2. Integrate Google Books API

We’ll use the Google Books API to fetch book data based on a search term.

Create your data model:

struct BookResponse: Codable {
    let items: [BookItem]
}
 
struct BookItem: Codable, Identifiable {
    let id: String
    let volumeInfo: VolumeInfo
}
 
struct VolumeInfo: Codable {
    let title: String
    let authors: [String]?
    let description: String?
}

Fetch books from the API:

class BookFetcher: ObservableObject {
    @Published var books: [BookItem] = []
    
    func fetchBooks(for query: String) {
        guard let encoded = query.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
              let url = URL(string: "https://www.googleapis.com/books/v1/volumes?q=\(encoded)") else { return }
        
        URLSession.shared.dataTask(with: url) { data, _, error in
            guard let data = data else { return }
            do {
                let result = try JSONDecoder().decode(BookResponse.self, from: data)
                DispatchQueue.main.async {
                    self.books = result.items
                }
            } catch {
                print("Failed to decode: \(error)")
            }
        }.resume()
    }
}

Ask Alex:
"Generate SwiftUI code that fetches books from the Google Books API and displays the title and author."


3. Build the Search UI

struct SearchView: View {
    @State private var searchText = ""
    @StateObject private var fetcher = BookFetcher()
    
    var body: some View {
        NavigationView {
            VStack {
                TextField("Search for books...", text: $searchText, onCommit: {
                    fetcher.fetchBooks(for: searchText)
                })
                .padding()
                .textFieldStyle(RoundedBorderTextFieldStyle())
                
                List(fetcher.books) { book in
                    NavigationLink(destination: BookDetailView(book: book)) {
                        VStack(alignment: .leading) {
                            Text(book.volumeInfo.title)
                                .font(.headline)
                            if let authors = book.volumeInfo.authors {
                                Text(authors.joined(separator: ", "))
                                    .font(.subheadline)
                                    .foregroundColor(.gray)
                            }
                        }
                    }
                }
            }
            .navigationTitle("Book Finder")
        }
    }
}

4. Book Detail View

struct BookDetailView: View {
    let book: BookItem
 
    var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 16) {
                Text(book.volumeInfo.title)
                    .font(.title)
                    .bold()
 
                if let authors = book.volumeInfo.authors {
                    Text("By \(authors.joined(separator: ", "))")
                        .foregroundColor(.secondary)
                }
 
                if let description = book.volumeInfo.description {
                    Text(description)
                        .padding(.top, 8)
                }
            }
            .padding()
        }
        .navigationTitle("Details")
    }
}

Ask Alex:
"Add slide transition and padding to a detail view with book info."


5. Polish & Refinement

Improve UX with loading states, transitions, and error handling.

Add a loading spinner:

if fetcher.books.isEmpty && !searchText.isEmpty {
    ProgressView("Loading...")
}

Alex can help:

  • Suggesting transitions (.transition(.slide))
  • Improving performance
  • Identifying unwrapped optionals that might crash

6. Next Steps

In the next tutorial, we’ll:

  • Add bookmarking for favorite books
  • Cache images and search results
  • Improve search with debouncing

Try this on your own:
"Alex, add a heart button to each book cell and save favorites using UserDefaults."


Conclusion

You just built a complete Book Finder App using:

  • SwiftUI + Combine
  • Google Books API
  • Alex AI Assistant to accelerate development

Explore what else Alex can do for you—from image-to-code to debugging SwiftUI layouts—all by using natural commands.

👉 Try Alex for free

Happy building!