0
0
iOS Swiftmobile~10 mins

Modularization 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 define a Swift module named "Utilities".

iOS Swift
public struct [1] {
    public static func greet() -> String {
        return "Hello from Utilities!"
    }
}
Drag options to blanks, or click blank then click option'
AApp
BMain
CUtilities
DCore
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated names like Main or Core.
Leaving the struct unnamed.
2fill in blank
medium

Complete the code to import the module named "Networking" in a Swift file.

iOS Swift
import [1]
Drag options to blanks, or click blank then click option'
AFoundation
BUIKit
CCoreData
DNetworking
Attempts:
3 left
💡 Hint
Common Mistakes
Importing UIKit instead of Networking.
Forgetting to import the module.
3fill in blank
hard

Fix the error in the code by completing the access control keyword to expose the function outside the module.

iOS Swift
struct Helper {
    [1] func performTask() {
        print("Task performed")
    }
}
Drag options to blanks, or click blank then click option'
Apublic
Bfileprivate
Cprivate
Dinternal
Attempts:
3 left
💡 Hint
Common Mistakes
Using private or fileprivate which hide the function.
Assuming internal allows external access.
4fill in blank
hard

Fill both blanks to define a protocol and make a class conform to it in Swift.

iOS Swift
protocol [1] {
    func execute()
}

class Task: [2] {
    func execute() {
        print("Executing task")
    }
}
Drag options to blanks, or click blank then click option'
ARunnable
BTask
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as the protocol name.
Not listing the protocol after the class name.
5fill in blank
hard

Fill all three blanks to create a Swift package with a public struct and a public method.

iOS Swift
public struct [1] {
    public func [2]() -> String {
        return "[3]"
    }
}
Drag options to blanks, or click blank then click option'
ALogger
BlogMessage
CLogging successful
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase struct names.
Not making the method public.
Returning unrelated strings.