Time Limit: 2 Hours
A simplified chat interface that simulates a conversation with an Mock AI assistant. This project was an interview test and had to be built in 2 hours.
- Chat Interface: Display messages in a scrollable list
- Message Input: Text field with send button
- Mock AI Responses: Simulate AI responses with predefined logic
- Message Types: Support user and assistant message bubbles with different styling
- Auto-scroll: Automatically scroll to newest messages
- Used SwiftUI for all UI components
- Implemented MVVM pattern with proper separation of concerns
- Handled basic error states (empty messages, etc.)
- Used async/await for simulated network delays
- Implement proper state management
-
Mock AI Service – Simulates an AI response system with network delay, random errors, and context-aware replies (greetings, questions, code-related, or default)
-
Chat ViewModel – Manages chat state, handles user input, communicates asynchronously with the AI service, and updates UI state including loading and error messages
-
iOS Specifications – Runs on iOS 16+
-
ChatInputView – TextField for user input, Send button enabled/disabled based on
canSendMessage, submit on return key, loading indicator withProgressView, error message display with dismiss button, proper padding and background styling. -
ChatView – Main chat screen with VStack layout:
- Empty state view when there are no messages.
- ScrollView + LazyVStack for messages.
- ScrollViewReader for auto-scrolling to the newest message.
- Smooth animation for auto-scroll when new messages arrive.
- ChatInputView pinned at the bottom.
- Clear button in navigation bar to reset chat.
-
MessageBubbleView – Displays individual messages with:
- Separate styling for user vs assistant.
- Rounded corners and padding inside bubbles.
- Max width for readability.
- Spacer usage for proper alignment.
- Refactored into two helper methods:
userBubble()andassistantBubble()for maintainability.
-
Mock AI Service Responses with Emojis – Added friendly emojis to assistant replies to make interactions more engaging and expressive.
- Add more text animations for a lively chat experience, such as animated typing dots, smooth message fade-ins
- Add an option to search messages within the chat session for easy reference to previous conversations
- Integrate a real AI API (e.g., OpenAI, GPT) to provide dynamic chatbot responses instead of static mock replies.
- Include message timestamps or “read receipts” for a more realistic chat interface.