Practice 50 SwiftUI Programming Questions, TechnoVlogs

Practice 50 SwiftUI Programming Questions


Q1. Write a SwiftUI program to display a simple "Hello, World!" text label.
  Input: None.
  Output: "Hello, World!" displayed on the screen.

Q2. Write a SwiftUI program to create a button that prints "Button clicked" when tapped.
  Input: A button labeled "Click Me".
  Output: "Button clicked" printed to the console.

Q3. Write a SwiftUI program to display an image from the asset catalog.
  Input: Image named "exampleImage".
  Output: "exampleImage" displayed on the screen.

Q4. Write a SwiftUI program to create a TextField where the user can input their name, and display it as a greeting.
  Input: Name entered by the user.
  Output: "Hello, [User's Name]" displayed on the screen.

Q5. Write a SwiftUI program to create a toggle that changes the background color from red to green.
  Input: Toggle switch.
  Output: Background color changes based on toggle state.

Q6. Write a SwiftUI program to display a vertical stack of two text labels.
  Input: Two Text views with different content.
  Output: Text labels displayed in a vertical stack.

Q7. Write a SwiftUI program to create a list of numbers and display them in a vertical list view.
  Input: Numbers array [1, 2, 3, 4, 5].
  Output: A list displaying numbers 1 through 5.

Q8. Write a SwiftUI program to implement a button that increases a counter when pressed.
  Input: Button labeled "Increment".
  Output: Counter value increments by 1 on each tap.

Q9. Write a SwiftUI program to implement a slider that adjusts a text label's font size.
  Input: Slider with range from 10 to 100.
  Output: Font size of the text changes based on slider value.

Q10. Write a SwiftUI program to display a simple form with two text fields for first and last names, and a submit button.
   Input: First name and last name entered in text fields.
   Output: Names displayed on button press.

Q11. Write a SwiftUI program to create a simple progress bar that fills up as a task progresses.
   Input: Progress value (0 to 1).
   Output: Progress bar fills based on the value.

Q12. Write a SwiftUI program to create a rounded button that prints a message when tapped.
   Input: A button labeled "Tap Me".
   Output: "Button tapped!" printed when tapped.

Q13. Write a SwiftUI program to create a tab view with two tabs: one with a text label and another with an image.
   Input: Two tabs with Text and Image.
   Output: Display the tab view with both tabs accessible.

Q14. Write a SwiftUI program to implement a VStack with different colors as its children.
   Input: VStack with three colored views.
   Output: Vertical stack with colored views.

Q15. Write a SwiftUI program to create a button that toggles the visibility of a text label.
   Input: Button "Show/Hide Text".
   Output: Text appears or disappears when button is clicked.

Q16. Write a SwiftUI program to create a DatePicker that displays the selected date.
   Input: DatePicker control.
   Output: Selected date displayed below the DatePicker.

Q17. Write a SwiftUI program to create a rounded image with a border.
   Input: Image to be rounded and bordered.
   Output: Rounded image with a border displayed.

Q18. Write a SwiftUI program to display a list of names and allow the user to select one.
   Input: List of names like ["Alice", "Bob", "Charlie"].
   Output: Selected name displayed.

Q19. Write a SwiftUI program to create a switch that changes text color between red and blue.
   Input: Switch control.
   Output: Text color toggles between red and blue based on switch state.

Q20. Write a SwiftUI program to implement a circular progress indicator that shows task progress.
   Input: Progress value (0 to 100).
   Output: Circular progress indicator showing completion percentage.

Q21. Write a SwiftUI program to display a list of items with custom styling for each row.
   Input: List of items with names and descriptions.
   Output: Each item displayed with custom styling (like bold text, icons).

Q22. Write a SwiftUI program to create a simple search bar and filter a list of items based on input.
   Input: A list of items and a search text field.
   Output: List filtered based on search input.

Q23. Write a SwiftUI program to create a view that displays a countdown timer.
   Input: Timer countdown starting from 10 seconds.
   Output: Countdown timer displayed and updated.

Q24. Write a SwiftUI program to display an alert when a button is tapped.
   Input: Button labeled "Show Alert".
   Output: Alert with a message displayed.

Q25. Write a SwiftUI program to implement a switch that toggles between two views.
   Input: A switch labeled "Toggle View".
   Output: Different views displayed based on switch state.

Q26. Write a SwiftUI program to display a vertical list of items where each item is clickable.
   Input: List of clickable items like ["Item 1", "Item 2"].
   Output: Item clicked shows a message like "You selected Item 1".

Q27. Write a SwiftUI program to create a horizontal stack of buttons that change their background color when tapped.
   Input: Buttons with labels "Button 1", "Button 2".
   Output: Buttons' background colors change when tapped.

Q28. Write a SwiftUI program to create a form with a text field and a button that clears the field.
   Input: Text field with input and a button labeled "Clear".
   Output: Text field cleared when button tapped.

Q29. Write a SwiftUI program to implement a segmented control that displays different text based on the selected segment.
   Input: Segmented control with options "First", "Second".
   Output: Display text based on selected segment.

Q30. Write a SwiftUI program to create a date picker with a specific date range.
   Input: DatePicker with a range from January 1, 2020, to December 31, 2025.
   Output: Selected date displayed.

Q31. Write a SwiftUI program to implement a view that scales up when the user taps on it.
   Input: Image or text tapped.
   Output: View scales up when tapped.

Q32. Write a SwiftUI program to create a custom view modifier that applies padding and a border.
   Input: View with custom modifier.
   Output: View with padding and border applied.

Q33. Write a SwiftUI program to create a List with sections and header titles.
   Input: List of items with different categories.
   Output: List with sections and corresponding headers.

Q34. Write a SwiftUI program to create a button that triggers a background color change.
   Input: Button labeled "Change Color".
   Output: Background color changes when button is clicked.

Q35. Write a SwiftUI program to create a carousel view with multiple images that can be swiped.
   Input: List of images to be swiped through.
   Output: Carousel view where images can be swiped.

Q36. Write a SwiftUI program to implement a simple drawer navigation menu.
   Input: Side menu with items.
   Output: Display menu that slides in and out.

Q37. Write a SwiftUI program to create a simple list view with a custom row layout.
   Input: List with custom row content like images and text.
   Output: List with custom styling for rows.

Q38. Write a SwiftUI program to create a checkbox view that updates a value when checked or unchecked.
   Input: Checkbox control.
   Output: Checkbox checked state changes.

Q39. Write a SwiftUI program to create a view that resizes according to the device orientation (portrait/landscape).
   Input: View adjusted to screen orientation.
   Output: View adjusts layout on rotation.

Q40. Write a SwiftUI program to implement a "Show More" button that expands a text view.
   Input: Button "Show More" and text content.
   Output: Text expands when the button is pressed.

Q41. Write a SwiftUI program to create a custom slider with a label showing the current value.
   Input: Slider with range from 0 to 100.
   Output: Label updates to show the current slider value.

Q42. Write a SwiftUI program to implement a simple refresh control to reload a list of items.
   Input: List with refresh control.
   Output: List reloads when user pulls to refresh.

Q43. Write a SwiftUI program to create a stacked card view with draggable elements.
   Input: Draggable cards.
   Output: Cards stacked and draggable.

Q44. Write a SwiftUI program to create a floating action button that performs an action when clicked.
   Input: Floating button with an action.
   Output: Action performed when button clicked.

Q45. Write a SwiftUI program to implement a custom font style in a text view.
   Input: Text view with a custom font.
   Output: Text displayed with the custom font.

Q46. Write a SwiftUI program to create a dismissable modal view.
   Input: Modal view with a button to close it.
   Output: Modal view closes when button tapped.

Q47. Write a SwiftUI program to create a toggle with a label that displays its state.
   Input: Toggle labeled "Enable Feature".
   Output: Label updates to show whether the toggle is on or off.

Q48. Write a SwiftUI program to implement a button with a custom background gradient.
   Input: Button with a gradient background.
   Output: Button displayed with gradient background.

Q49. Write a SwiftUI program to create a pop-up notification that appears after a delay.
   Input: Timer that triggers the pop-up.
   Output: Notification displayed after delay.

Q50. Write a SwiftUI program to create a custom list row with an image, title, and description.
   Input: List of items with images, titles, and descriptions.
   Output: List with custom-styled rows.

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!