An open-source iOS SwiftUI sample that demonstrates a modern posts feed backed by a REST API using layered Clean Architecture. The project showcases the native iOS APIs for UI, networking, local persistence, and dependency injection.
For this app, please have a look at my open source Posts Rest API repository. Configure it by following the instructions and run the local server so this app works correctly (default port:
3000).
- Highlights
- Architecture Overview
- Tech Stack
- Project Structure
- Getting Started
- Local API Notes
- Roadmap Ideas
- Contributing
- 100% Swift with SwiftUI navigation and a tab-based shell (
Home,Favorites,Settings). - Clean layers (
data,domain,presentation) with protocol-driven boundaries. - Dependency injection with Swinject through a single
AppContainerroot. - Async networking with
URLSessionand Swift concurrency (async/await). - Post detail resolves author and comments using dedicated use cases.
- Favorites persist locally using
UserDefaultsand sync across tabs. - Pull-to-refresh and reusable error/empty state components.
PostsApp (SwiftUI App)
|
+- data/di AppContainer (Swinject registrations)
| +- NetworkManager (URLSession)
| +- Repositories (Post, User, Comment, Favorite)
| +- Local store (FavoriteStore)
|
+- domain (entities + repository contracts + use cases)
|
+- presentation (screens + components + view models)
+- HomeViewModel
+- PostDetailViewModel
+- SwiftUI screens (Home/Favorites/PostDetail/Profile/Settings)
- State Management:
ObservableObjectview models publish screen state (posts, loading/error flags, author/comments details). - Navigation:
NavigationStackinside each tab and detail navigation from post cards. - Feature parity with Android: posts list, favorite toggles, persisted favorites, post detail author fetch, and comments rendering.
- Swift 5.9+
- SwiftUI
- URLSession
- Swift Concurrency
- Swinject
- UserDefaults (favorite persistence)
- Xcode 16+ tooling
PostsApp/
|- data/
| |- di/ # AppContainer registrations
| |- dto/ # API DTOs (PostDto, UserDto, CommentDto)
| |- local/ # Local storage adapters (FavoriteStore)
| |- mapper/ # DTO <-> domain mappers
| |- network/ # NetworkManager + protocol
| |- protocol/ # Mapper/network protocols
| |- repository/ # Repository implementations
|
|- domain/
| |- entity/ # Post, User, Comment
| |- repository/ # Repository contracts
| |- usecase/ # GetPosts, GetUserById, GetComments, favorites use cases
|
|- presentation/
| |- component/ # Reusable UI components
| |- navigation/ # Bottom tab shell
| |- screen/ # Auth/Home/Favorites/PostDetail/Profile/Settings
| |- support/ # Environment helpers
| |- viewModel/ # HomeViewModel, PostDetailViewModel
- Clone the repository:
git clone https://github.com/hassaanjamil/SampleIOSPostsApp.git cd SampleIOSPostsApp - Start the local API (
http://127.0.0.1:3000) using your preferred backend or JSON server. - Open
PostsApp.xcodeprojin Xcode. - Select the
PostsAppscheme and run on an iOS simulator.
- macOS with Xcode 16+
- iOS 17+ simulator or physical device
- Swift 5.9+
xcodebuild \
-project PostsApp.xcodeproj \
-scheme PostsApp \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 16' \
clean test- Endpoints used by this app:
GET /postsGET /users/:idGET /comments/:postId
- Need instant mock data? You can run JSON Server:
npx json-server --watch db.json --port 3000
- Add full unit tests for each layer and integration tests for view model flows.
- Replace mock auth gate with a real sign-in flow.
- Add offline-first caching for posts/comments.
- Add advanced filtering/sorting for posts and favorites.
Pull requests, issues, and ideas for improvements are welcome.
- Star the repo.
- Create a feature branch.
- Add or update tests.
- Run local checks.
- Open a pull request.