A comprehensive fitness tracking app built with SwiftUI that helps you monitor body weight, gym workouts, and nutrition intake.
- โ Daily weight entry with duplicate prevention
- โ Interactive line chart showing weight trends
- โ Optional weekly average visualization
- โ Historical data view
- โ Support for Push, Pull, Legs, Cardio workouts
- โ Log exercises with sets, reps, and weight
- โ Track personal records
- โ Visual progress charts per exercise
- โ Search foods using USDA FoodData Central API
- โ Automatic macro calculation (calories, protein, carbs, fat)
- โ Manual quantity adjustment
- โ Daily nutrition summary
- SwiftUI: Modern declarative UI framework
- Core Data: Local data persistence
- Apple Charts: Native charting framework
- MVVM Architecture: Clean separation of concerns
- Dark Mode: Full support
FitTrackApp/
โโโ FitTrackApp.swift # App entry point
โโโ ContentView.swift # Main tab navigation
โโโ Models/
โ โโโ CoreData/
โ โ โโโ FitTrackModel.xcdatamodeld # Core Data schema
โ โ โโโ PersistenceController.swift # Core Data stack
โ โโโ DTOs/
โ โโโ FoodSearchResult.swift # USDA API models
โ โโโ NutritionInfo.swift # Nutrition structures
โโโ ViewModels/
โ โโโ WeightViewModel.swift # Weight logic
โ โโโ WorkoutViewModel.swift # Workout logic
โ โโโ DietViewModel.swift # Diet logic
โโโ Views/
โ โโโ Weight/
โ โ โโโ WeightTrackingView.swift
โ โ โโโ WeightChartView.swift
โ โโโ Workout/
โ โ โโโ WorkoutListView.swift
โ โ โโโ AddWorkoutView.swift
โ โ โโโ ExerciseProgressView.swift
โ โโโ Diet/
โ โโโ DietTrackingView.swift
โ โโโ FoodSearchView.swift
โ โโโ AddFoodView.swift
โโโ Services/
โ โโโ USDAFoodService.swift # API integration
โโโ Utilities/
โโโ DateExtensions.swift # Date helpers
โโโ Constants.swift # App constants
- macOS 13.0 or later
- Xcode 15.0 or later
- iOS 17.0+ deployment target
-
Open Xcode
- Launch Xcode from your Applications folder
-
Create New Project
- Click "Create a new Xcode project"
- Select "iOS" โ "App"
- Click "Next"
-
Configure Project
- Product Name:
FitTrackApp - Team: Select your Apple ID (or leave as "None" for simulator only)
- Organization Identifier:
com.yourname.fittrack - Interface: SwiftUI
- Storage: Core Data (CHECK THIS BOX!)
- Language: Swift
- Click "Next" and choose save location
- Product Name:
-
Add Files to Project
- In Xcode's left sidebar (Project Navigator), right-click on "FitTrackApp" folder
- Select "New Group" and create these folders:
- Models
- ViewModels
- Views
- Services
- Utilities
- For each
.swiftfile in this repository:- Right-click the appropriate folder
- Select "New File" โ "Swift File"
- Name it exactly as shown
- Copy and paste the code from this repository
-
Configure Core Data
- Delete the default
.xcdatamodeldfile if it exists - Add the
FitTrackModel.xcdatamodeldfile from this repo
- Delete the default
-
Add Required Frameworks
- Select your project in the navigator
- Go to "General" tab
- Under "Frameworks, Libraries, and Embedded Content", ensure:
- CoreData.framework is present
- Charts framework (iOS 16+)
-
Configure Info.plist for API Access
- Select Info.plist
- Add key:
NSAppTransportSecurity - Add child:
NSAllowsArbitraryLoads= YES - (Note: For production, configure specific domain exceptions)
-
Get USDA API Key (Free)
- Visit: https://fdc.nal.usda.gov/api-key-signup.html
- Sign up for a free API key
- Open
Services/USDAFoodService.swift - Replace
"YOUR_API_KEY_HERE"with your actual key
-
Build and Run
- Select a simulator (e.g., iPhone 15 Pro)
- Press โR or click the Play button
- Wait for build to complete
- App will launch in simulator
Build Errors:
- Ensure all files are added to the target (check File Inspector)
- Clean build folder: Product โ Clean Build Folder (โงโK)
- Restart Xcode if needed
Core Data Errors:
- Verify
.xcdatamodeldfile is included in target - Check PersistenceController is properly initialized
API Not Working:
- Verify API key is correctly entered
- Check internet connection in simulator
- Review console logs for error messages
- Tap "Weight" tab
- Enter your weight in pounds or kg
- Tap "Add Weight"
- View your progress on the chart
- Toggle "Show Weekly Average" for smoothed trend
- Tap "Workouts" tab
- Tap "+" to add new workout
- Select workout type (Push/Pull/Legs/Cardio)
- Add exercises with sets, reps, weight
- Save workout
- View history and progress charts
- Tap "Diet" tab
- Tap "Add Food"
- Search for food using USDA database
- Adjust serving size
- Add to daily log
- View daily macro summary
- Models: Data structures (Core Data entities)
- Views: UI components (SwiftUI)
- ViewModels: Business logic and data management
- Local database on device
- Persistent storage across app launches
- Efficient querying and relationships
- Modularity: Each feature is self-contained
- Testability: ViewModels can be tested independently
- Maintainability: Easy to find and update code
- Scalability: Simple to add new features
- iCloud sync across devices
- Export data to CSV/PDF
- Workout templates and routines
- Nutrition goals and targets
- Progress photos with timeline
- Apple Health integration
- Widgets for home screen
- Apple Watch companion app
- Meal planning and recipes
- Barcode scanner for food
- Social features and sharing
- AI-powered workout suggestions
- Integration with fitness trackers
- Custom exercise library
- Advanced analytics and insights
- Comments: Every function and complex logic explained
- Naming: Clear, descriptive variable and function names
- Formatting: Consistent indentation and spacing
- Error Handling: Graceful failures with user feedback
For issues or questions:
- Check console logs in Xcode (โโงY)
- Review error messages carefully
- Verify all setup steps completed
- Check Apple Developer documentation
This is a learning project. Feel free to modify and use for personal projects.
Built with โค๏ธ using SwiftUI