CodeCompletion.io

Episode 25: Subjective-C

Welcome to Code Completion, Episode 25! We are a group of iOS developers and educators hoping to share what we love most about development, Apple technology, and completing your code!

Follow us @CodeCompletion on Twitter to hear about our upcoming livestreams, videos, and other content.

Be sure to also sign up to our monthly newsletter, where we will recap the topics we discussed, reveal the answers to #CompleteTheCode, and share even more things we learned in between episodes.

You are what makes this show possible, so please be sure to share this with your friends and family who are also interested in any part of the app development process.

⭐️ This Week's Topics

  • The relevance of Objective-C for new and existing developers.
  • The complexity of Swift.
  • SwiftUI vs UIKit.

🚧 #CompleteTheCode

This week's #CompleteTheCode:

Can you spot and fix the memory leak?
1
2
3
4
5
6
7
8
9
10
11
12
class DelayedTask {
    var complete = false
    var task: DispatchWorkItem?
    
    func configure() {
        task = DispatchWorkItem {
            DispatchQueue.main.asyncAfter(.now() + 5) { [weak self] in
                self?.complete = true
            }
        }
    }
}

Be sure to tweet us with hashtag #CompleteTheCode if you know the answer!

⚠️ Compiler Error

This week's theme: Objective-C ARC!

  1. Much like Swift, ARC can be configured to operate on CoreFoundation types in Objective-C code using the option -f-objc-arc-cftypes at compile time.
  1. Automatic Reference Counting was originally called Automatic Retain Release, abbreviated as ARR, and was ultimately changed to ARC before release.
  1. Unlike with ARC, Objective-C Garbage Collection required users to implement -finalize rather than -dealloc for object cleanup.
  1. Although they were introduced with ARC, @autoreleasepool blocks can also be used in code where ARC is disabled since it offers a performance improvement.
Compilation Results

This time, Fernando went first, followed by Ben and Spencer. Let's see how they did!

4. Although they were introduced with ARC, @autoreleasepool blocks can also be used in code where ARC is disabled since it offers a performance improvement.

Ben and Spencer believed this to be true, but Fernando thought it must be wrong… which he was wrong to think, because it was a code completion!

3. Unlike with ARC, Objective-C Garbage Collection required users to implement -finalize rather than -dealloc for object cleanup.

Everyone thought this was plausible, since it was also a code completion!

2. Automatic Reference Counting was originally called Automatic Retain Release, abbreviated as ARR, and was ultimately changed to ARC before release.

No one was tricked by the pirate sounding accronym, because it is also a code completion!

Which means…

1. Much like Swift, ARC can be configured to operate on CoreFoundation types in Objective-C code using the option -f-objc-arc-cftypes at compile time.

Both Ben and Spencer trusted their gut, which payed off since this was the compiler error! Only Swift got this magical functionality through its C overlay, which Objective-C can't participate in to this day…

Learn More →

🎁 Sponsor

This week's episode of Code Completion is brought to you by Underdog Devs' Spring Into Swift event. Follow @UnderdogDevs and be sure to follow Bon Voyage's instructor @jonnybcodes on Twitter to learn more and stay tuned for more information about the Spring Into Swift event!

📺 Watch the Stream