Skip to content

Commit 461ee79

Browse files
committed
feat: Major Project Refactoring and New 'Hello World (with template)' Feature
This commit introduces a significant refactoring of the iOS project, reorganizing the codebase into a more modular and maintainable structure. All feature-specific code has been moved into a new `Features` directory, while shared components (Models, Views) are now centralized under a `Shared` directory. Key changes include: - **Project Structure Reorganization**: - Created `FirebaseAIExample/Features` to house individual feature modules (e.g., `Chat`, `FunctionCalling`, `GenerativeAIText`, `Grounding`, `Imagen`, `Multimodal`). - Created `FirebaseAIExample/Shared` for common models, views, and utilities. - Updated `FirebaseAIExample.xcodeproj/project.pbxproj` to reflect the new file paths and group structure. - **New Feature: 'Hello world (with template)'**: - Implemented `GenerateContentFromTemplateScreen` and `GenerateContentFromTemplateViewModel` under `Features/GenerativeAIText`. - This feature demonstrates server-side template generation using the `apple-qs-greeting` template. - Registered the new feature in `ContentView` and added a corresponding `Sample` entry in `Sample.swift` with the title "Hello world (with template)". - **Bug Fixes and Best Practices**: - **Security Fix**: Replaced insecure API key initialization in `GenerateContentFromTemplateViewModel` with the secure `FirebaseAI.firebaseAI(backend:)` factory method. - **Compile Error Resolution**: Moved shared UI components (`ProgressOverlay.swift`, `ErrorDetailsView.swift`) into `FirebaseAIExample/Shared/Views` to resolve compile errors and ensure global accessibility. - **Centralized BackendOption**: Extracted the `BackendOption` enum into its own file (`FirebaseAIExample/Shared/Models/BackendOption.swift`) for better code organization and reusability. This refactoring significantly improves the project's scalability, readability, and adherence to modern Swift/SwiftUI architectural patterns.
1 parent bfba576 commit 461ee79

38 files changed

+537
-685
lines changed

firebaseai/FirebaseAIExample.xcodeproj/project.pbxproj

Lines changed: 92 additions & 424 deletions
Large diffs are not rendered by default.

firebaseai/FirebaseAIExample.xcodeproj/xcshareddata/xcschemes/FirebaseAIExample (iOS).xcscheme

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
buildForAnalyzing = "YES">
1616
<BuildableReference
1717
BuildableIdentifier = "primary"
18-
BlueprintIdentifier = "8848C82E2B0D04BC007B434F"
18+
BlueprintIdentifier = "88779D342EC8A9CF0080D023"
1919
BuildableName = "FirebaseAIExample.app"
2020
BlueprintName = "FirebaseAIExample"
2121
ReferencedContainer = "container:FirebaseAIExample.xcodeproj">
@@ -44,7 +44,7 @@
4444
runnableDebuggingMode = "0">
4545
<BuildableReference
4646
BuildableIdentifier = "primary"
47-
BlueprintIdentifier = "8848C82E2B0D04BC007B434F"
47+
BlueprintIdentifier = "88779D342EC8A9CF0080D023"
4848
BuildableName = "FirebaseAIExample.app"
4949
BlueprintName = "FirebaseAIExample"
5050
ReferencedContainer = "container:FirebaseAIExample.xcodeproj">
@@ -67,7 +67,7 @@
6767
runnableDebuggingMode = "0">
6868
<BuildableReference
6969
BuildableIdentifier = "primary"
70-
BlueprintIdentifier = "8848C82E2B0D04BC007B434F"
70+
BlueprintIdentifier = "88779D342EC8A9CF0080D023"
7171
BuildableName = "FirebaseAIExample.app"
7272
BlueprintName = "FirebaseAIExample"
7373
ReferencedContainer = "container:FirebaseAIExample.xcodeproj">

firebaseai/FirebaseAIExample/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
{
22
"images" : [
33
{
4+
"filename" : "Firebase AI Logic.png",
5+
"idiom" : "universal",
6+
"platform" : "ios",
7+
"size" : "1024x1024"
8+
},
9+
{
10+
"appearances" : [
11+
{
12+
"appearance" : "luminosity",
13+
"value" : "dark"
14+
}
15+
],
16+
"idiom" : "universal",
17+
"platform" : "ios",
18+
"size" : "1024x1024"
19+
},
20+
{
21+
"appearances" : [
22+
{
23+
"appearance" : "luminosity",
24+
"value" : "tinted"
25+
}
26+
],
427
"idiom" : "universal",
528
"platform" : "ios",
629
"size" : "1024x1024"
126 KB
Loading

firebaseai/FirebaseAIExample/ContentView.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@
1313
// limitations under the License.
1414

1515
import SwiftUI
16-
import FirebaseAI
17-
18-
enum BackendOption: String, CaseIterable, Identifiable {
19-
case googleAI = "Gemini Developer API"
20-
case vertexAI = "Vertex AI Gemini API"
21-
22-
var id: String { rawValue }
23-
}
16+
import FirebaseAILogic
2417

2518
struct ContentView: View {
2619
@State private var selectedBackend: BackendOption = .googleAI
@@ -107,6 +100,10 @@ struct ContentView: View {
107100
ChatScreen(backendType: selectedBackend, sample: sample)
108101
case "ImagenScreen":
109102
ImagenScreen(backendType: selectedBackend, sample: sample)
103+
case "ImagenFromTemplateScreen":
104+
ImagenFromTemplateScreen(backendType: selectedBackend, sample: sample)
105+
case "GenerateContentFromTemplateScreen":
106+
GenerateContentFromTemplateScreen(backendType: selectedBackend, sample: sample)
110107
case "MultimodalScreen":
111108
MultimodalScreen(backendType: selectedBackend, sample: sample)
112109
case "FunctionCallingScreen":

firebaseai/FirebaseAIExample/ChatExample/Models/ChatMessage.swift renamed to firebaseai/FirebaseAIExample/Features/Chat/Models/ChatMessage.swift

File renamed without changes.

firebaseai/FirebaseAIExample/ChatExample/Screens/ChatScreen.swift renamed to firebaseai/FirebaseAIExample/Features/Chat/Screens/ChatScreen.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import FirebaseAI
15+
#if canImport(FirebaseAILogic)
16+
import FirebaseAILogic
17+
#else
18+
import FirebaseAI
19+
#endif
1620
import SwiftUI
1721
import ConversationKit
1822

firebaseai/FirebaseAIExample/ChatExample/ViewModels/ChatViewModel.swift renamed to firebaseai/FirebaseAIExample/Features/Chat/ViewModels/ChatViewModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#endif
2020
import Foundation
2121
import UIKit
22+
import Combine
23+
import ConversationKit
2224

2325
@MainActor
2426
class ChatViewModel: ObservableObject {

firebaseai/FirebaseAIExample/ChatExample/Views/BouncingDots.swift renamed to firebaseai/FirebaseAIExample/Features/Chat/Views/BouncingDots.swift

File renamed without changes.

firebaseai/FirebaseAIExample/ChatExample/Views/MessageView.swift renamed to firebaseai/FirebaseAIExample/Features/Chat/Views/MessageView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import MarkdownUI
1616
import SwiftUI
1717
#if canImport(FirebaseAILogic)
1818
import FirebaseAILogic
19+
import ConversationKit
1920
#else
2021
import FirebaseAI
2122
#endif

0 commit comments

Comments
 (0)