Skip to Content
Course content

133: Timed Mock Assessment on Core Swift

Click on the "Edit" button in the top corner of the screen to edit your slide content.

Think of this lesson like a scrimmage in sports or a dress rehearsal for a play. You've spent the last hundred-plus lessons learning the plays, practicing your footwork, and memorizing the lines. But there's a massive difference between practicing a move in slow motion and having to execute it while the game clock is ticking and the pressure is on. In a real job, you'll have documentation and StackOverflow, but in a technical interview or a high-stakes sprint, you need a certain level of "muscle memory" where the syntax just flows without you having to stop and think, "Wait, is it some or any here?"

That's exactly what this mock assessment is. We're mapping the "scrimmage" to your Swift knowledge: the clock represents the constraints of a real-world technical screen, the problems represent the core architectural patterns we've covered, and the mistakes you make now are the "bruises" that teach you exactly where your knowledge gaps are before they matter in a production environment.

The Psychology of the Timer

I've seen brilliant engineers freeze up during timed assessments. It usually happens because they treat the timer as a threat rather than a tool. When you start this mock, you'll likely hit a wall—maybe a tricky question on weak vs unowned references or a complex generic constraint. My advice? If you spend more than three minutes staring at a single line of code without typing, move on. In a real assessment, getting 80% of four problems right is infinitely better than getting 100% of one problem right and leaving the rest blank.

Where the Brain Freeze Usually Happens

In my experience, when developers rush, they tend to trip over the "invisible" parts of Swift. You'll likely remember how to write a for-in loop, but you might stumble on the nuances of escaping closures or the specific requirements of a Comparable protocol implementation. For example, if you're asked to implement a custom sorting algorithm for a User struct, don't forget that Comparable requires Comparable types to implement the < operator. It sounds simple, but under a timer, that's the kind of detail that slips.

Evaluating Your Performance

When the timer stops, don't just look at your score. That's the textbook way of doing it, and it's useless. Instead, look at why you missed a question. Did you actually forget the concept (a knowledge gap), or did you know the answer but couldn't express it in code quickly enough (a fluency gap)? If it's the former, go back to those specific lessons. If it's the latter, you just need more repetitions. I've spent years writing Swift, and I still occasionally fumble a complex flatMap chain if I haven't done it in a few weeks. It's all about keeping the gears greased.




📋 Practical Task

The Generic Repository Filter Implementation

To simulate a real-world assessment task, you need to build a generic filtering system. This tests your ability to combine Generics, Closures, and Optionals under pressure.

Your Task: Create a generic class called DataRepository. It should hold an array of items of a generic type T. Implement a method called findItems(where: ) that takes a closure as a predicate and returns an array of all items that match that predicate.

Requirements:

  • The DataRepository must be initialized with an initial array of items.
  • The findItems method must be generic enough to work with any type T.
  • The predicate closure should take an element of type T and return a Bool.
  • The Twist: Add a second method called findFirstItem(where: ) that returns an Optional of type T?, returning the first match it finds or nil if no match exists.
// Example of how your implementation should be called:
struct Product {
    let name: String
    let price: Double
}

let products = [Product(name: "Laptop", price: 1200), Product(name: "Mouse", price: 25)]
let repo = DataRepository(items: products)

let cheapStuff = repo.findItems { $0.price < 100 } 
// Should return [Product(name: "Mouse", price: 25)]

let expensiveItem = repo.findFirstItem { $0.name == "Laptop" }
// Should return Optional(Product(name: "Laptop", price: 1200))
Rating
0 0

There are no comments for now.

to be the first to leave a comment.