This is a sample code about using Advanced operation in swift.
The base sample code is taken from NSOperation and NSOperationQueue Tutorial in Swift - Ray Wenderlich and rewrited by using Advanced operation library of Advanced NSOperations - WWDC 2015 - Session 226.
First of all, if you haven't enough expriment about using operations in swift, have a look to raywenderlich tutorial. the starter and completed of raywenderlich tutorial sample codes are exist in this sample codes for comparing with advanced operation version. all sample codes are updated to swift 4 syntax.
Next, compare ClassicPhotos written with Advanced Operation and ClassicPhotos app created by raywenderlich tutorial. look at differences in codes and runing. for more information about using advanced operation watch Advanced NSOperations - WWDC 2015 - Session 226 Video.
You will see:
-
How the code is encapsulated and more readable and more understandable. You can detect easily what is the duty of each file and even each method.
-
How loading images and their filtering is speeded up and being more efficient.
-
Notice that the app improvement isn't cause just using advanced Operations, I converted
PhotoRecord
class to struct. It was effective to improvement the app too. Look how I updatedphotos
arrray inListViewController
after receiving details from internet or after downloading or filtering images. I used protocol for this. Also I usedURLSession
instead of simpleData
for downloading images.
just import the Operations
folder inside the ClassicPhotos-Advanced-Operation Folder in to your project and use it.
Although this not a complete version of Advanced Operation library. you can download complete one from Advanced NSOperations - WWDC 2015 - Session 226 sample code.
I hope this sample code will be useful to you.