0
0
iOS Swiftmobile~10 mins

Cloud Storage 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 initialize a reference to the Firebase Storage root.

iOS Swift
let storage = Storage.storage()
let storageRef = storage.[1]
Drag options to blanks, or click blank then click option'
Areference()
Bref()
CrootReference()
Droot()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ref()' instead of 'reference()'.
Trying to use 'root()' which does not exist.
2fill in blank
medium

Complete the code to upload data to a file named "image.jpg" in Firebase Storage.

iOS Swift
let data = Data()
let imageRef = storageRef.child("[1]")
imageRef.putData(data, metadata: nil) { metadata, error in
  // handle completion
}
Drag options to blanks, or click blank then click option'
Aphoto.jpg
Bpicture.png
Cimage.jpg
Dimage.png
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'image.png' instead of 'image.jpg'.
Using a different file name like 'photo.jpg'.
3fill in blank
hard

Fix the error in the code to download data from Firebase Storage with a maximum size of 1MB.

iOS Swift
let imageRef = storageRef.child("image.jpg")
imageRef.getData(maxSize: [1]) { data, error in
  if let data = data {
    // use data
  }
}
Drag options to blanks, or click blank then click option'
A1024
B1024 * 1024
C1000000
D1_000_000_000
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1024 which is only 1KB.
Using 1_000_000 which is close but not exact bytes.
4fill in blank
hard

Fill both blanks to create a dictionary of file names and their sizes in bytes from metadata.

iOS Swift
var fileSizes = [String: Int64]()
for item in items {
  item.getMetadata { metadata, error in
    if let metadata = metadata {
      fileSizes[[1]] = metadata.[2]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aitem.name
Bitem.fullPath
Csize
DtotalBytes
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'item.fullPath' instead of 'item.name' for the file name.
Using 'totalBytes' instead of 'size' for the file size.
5fill in blank
hard

Fill all three blanks to delete a file named "oldfile.txt" from Firebase Storage and handle errors.

iOS Swift
let oldFileRef = storageRef.child("[1]")
oldFileRef.[2] { error in
  if let error = error {
    print("Failed to delete: \(error.localizedDescription)")
  } else {
    print("[3]")
  }
}
Drag options to blanks, or click blank then click option'
Aoldfile.txt
Bdelete(completion:)
Cdelete
DFile deleted successfully
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete(completion:)' which is not the correct method call syntax.
Using a wrong file name or success message.