iOS Concurrency with GCD and Operations - Part 10: | Ray Wenderlich

Audrey, what causes the spinner to appear?

I didn’t notice our doing any work to implement them. Are they built into one of the classes that we are using?

hi! it’s in ImageTableViewCell — activityIndicator

Attaching a Swift 5 Xcode 11 version of exercise files for this lecture, could probably help those who don’t have Xcode 10 to be able to run the demo. Did nothing but used the default migration tool, and can verify that the end product works just fine (albeit with 2-3 warnings)
Won’t mind if this is made downloadable directly from the lecture video page - http://f.cl.ly/items/0O201X2T3R0A310t3A2M/10_OperationsInPractice.zip

1 Like

Also, I have a question - Quite a basic one.
TiltShiftImage.swift file has a struct TiltShiftImage and a free floating function
func ==(lhs: TiltShiftImage, rhs: TiltShiftImage) → Bool {
return lhs.imageName == rhs.imageName && lhs.title == rhs.title
}
This is probably the first time I am seeing a function outside of a class or struct (outside of playgrounds) and I would like to know more about it.

I mean theoretically its a function and not a method, but that’s all the data I have about it. Is this equivalent to
extension TiltShiftImage: Equatable {
static func ==(lhs: TiltShiftImage, rhs: TiltShiftImage) → Bool {
return lhs.imageName == rhs.imageName && lhs.title == rhs.title
}
}

hi akashlal! overloading == inside the Equatable extension is certainly how it’s done in our tutorial.

I see “our tutorial” hyperlinked to https://www.raywenderlich.com/4018226-overloading-custom-operators-in-swift#toc-anchor-001, was that intentional?

wrong anchor: https://www.raywenderlich.com/4018226-overloading-custom-operators-in-swift#toc-anchor-002

Ah okay, got the reason for the linking now :slight_smile:

Coming back to the question, attaching a screenshot of the downloaded code without any modification - The extension is empty (just conforms to Equatable)
While the == function hangs outside, and is neither in the struct nor in the extension; but just works! How?
Screenshot 2020-05-01 at 6.17.23 PM

Swift allows global functions. But specifically for this case, I looked it up in our old Swift by Tutorials book (Swift 1.2 — the web page shows the wrong image and version info):

The extension is the usual way to declare conformance to a protocol, but notice that the == function is not inside the extension. You must declare all operator overloads at global scope because they aren’t methods that belong to a class – you can use the == operator on its own anywhere. They are only associated with a class in that the type of the two parameters are instances of the class the function is comparing.

This changed in a later version of Swift, so now the operator overloads are in the Equatable extension.

1 Like

@akashlal Please check out the updated version of the course when you get a chance:

https://www.raywenderlich.com/9461083-ios-concurrency-with-gcd-and-operations

I hope it helps!