0
0
iOS Swiftmobile~10 mins

Why platform APIs access device capabilities in iOS Swift - Test Your Understanding

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

Complete the code to import the framework that allows access to device features.

iOS Swift
import [1]
Drag options to blanks, or click blank then click option'
AFoundation
BUIKit
CCoreData
DAVFoundation
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing Foundation which is for basic data types and collections.
Choosing CoreData which is for data storage.
Choosing AVFoundation which is for audio and video.
2fill in blank
medium

Complete the code to request permission to use the device camera.

iOS Swift
AVCaptureDevice.requestAccess(for: .video) { granted in
    if [1] {
        print("Camera access granted")
    } else {
        print("Camera access denied")
    }
}
Drag options to blanks, or click blank then click option'
Agranted
Bpermission
Caccess
Dallowed
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the closure parameter.
Confusing the parameter with a permission object.
3fill in blank
hard

Fix the error in the code to get the current device orientation.

iOS Swift
let orientation = UIDevice.current.[1]
Drag options to blanks, or click blank then click option'
Aorientation
BdeviceOrientation
CcurrentOrientation
DorientationState
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names that do not exist.
Trying to access orientation from the wrong object.
4fill in blank
hard

Fill both blanks to create a dictionary that maps sensor names to their availability status.

iOS Swift
let sensors = ["Accelerometer": [1], "Gyroscope": [2]]
Drag options to blanks, or click blank then click option'
ACMMotionManager().isAccelerometerAvailable
BCMMotionManager().isGyroAvailable
CCMMotionManager().isMagnetometerAvailable
DCMMotionManager().isDeviceMotionAvailable
Attempts:
3 left
💡 Hint
Common Mistakes
Using properties for other sensors like magnetometer or device motion.
Mixing up the property names.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that filters sensors available on the device.

iOS Swift
let availableSensors = [
    [1]: [2] for [3] in ["Accelerometer", "Gyroscope", "Magnetometer"]
    if CMMotionManager().is[1]Available
]
Drag options to blanks, or click blank then click option'
Asensor
Btrue
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'false' as value which would be incorrect for available sensors.
Using different variable names inconsistently.