0
0
iOS Swiftmobile~10 mins

Camera and photo library in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the framework needed to access the photo library.

iOS Swift
import UIKit
import [1]
Drag options to blanks, or click blank then click option'
AMapKit
BPhotosUI
CCoreData
DAVFoundation
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated frameworks like CoreData or MapKit.
Forgetting to import PhotosUI when working with photo library.
2fill in blank
medium

Complete the code to declare a UIImagePickerController variable.

iOS Swift
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
  var imagePicker = [1]()
}
Drag options to blanks, or click blank then click option'
AUIImage
BUIImageView
CUIViewController
DUIImagePickerController
Attempts:
3 left
💡 Hint
Common Mistakes
Using UIImageView instead of UIImagePickerController.
Confusing UIViewController with UIImagePickerController.
3fill in blank
hard

Fix the error in the code to present the image picker for the photo library.

iOS Swift
func openPhotoLibrary() {
  imagePicker.sourceType = [1]
  present(imagePicker, animated: true)
}
Drag options to blanks, or click blank then click option'
AUIImagePickerController.SourceType.photoLibrary
BUIImagePickerController.SourceType.camera
CUIImagePickerController.SourceType.savedPhotosAlbum
DUIImagePickerController.SourceType.photoAlbum
Attempts:
3 left
💡 Hint
Common Mistakes
Using camera source type when wanting the photo library.
Using a non-existent source type like photoAlbum.
4fill in blank
hard

Fill both blanks to check if the camera is available and set the source type accordingly.

iOS Swift
if UIImagePickerController.isSourceTypeAvailable([1]) {
  imagePicker.sourceType = [2]
}
Drag options to blanks, or click blank then click option'
AUIImagePickerController.SourceType.camera
BUIImagePickerController.SourceType.photoLibrary
CUIImagePickerController.SourceType.savedPhotosAlbum
DUIImagePickerController.SourceType.cameraRoll
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for photoLibrary availability but setting camera source type.
Using non-existent source types like cameraRoll.
5fill in blank
hard

Fill all three blanks to implement the delegate method that handles the selected image.

iOS Swift
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
  if let selectedImage = info[[1]] as? [2] {
    imageView.image = selectedImage
  }
  picker.[3](animated: true, completion: nil)
}
Drag options to blanks, or click blank then click option'
AUIImagePickerController.InfoKey.originalImage
BUIImagePickerController.InfoKey.editedImage
CUIImage
Ddismiss
Attempts:
3 left
💡 Hint
Common Mistakes
Using editedImage key when originalImage is expected.
Not casting the image to UIImage.
Forgetting to dismiss the picker.