An open API service indexing awesome lists of open source software.

https://github.com/rodrigofrancisco/operationqueueexample

Example to show how to handle fetched data from REST API using OperationQueue instead GCD
https://github.com/rodrigofrancisco/operationqueueexample

example-code ios-swift

Last synced: over 1 year ago
JSON representation

Example to show how to handle fetched data from REST API using OperationQueue instead GCD

Awesome Lists containing this project

README

          

= Ejemplo de OperationQueue y Networking
Creado por Rodrigo Francisco
Version 1.0, 24.09.2021
// Ruta base de las imagenes
:imagesdir: ./README.assets/
// Resaltar sintaxis
:source-highlighter: pygments
// Iconos para entorno local
ifndef::env-github[:icons: font]
// Iconos para entorno github
ifdef::env-github[]
:caution-caption: :fire:
:important-caption: :exclamation:
:note-caption: :paperclip:
:tip-caption: :bulb:
:warning-caption: :warning:
endif::[]

Proyecto para el diplomado 5G iOS, módulo 3

[source,sh]
Septiembre de 2021
Autor: rhodfra@gmail.com
swift 5, iOS 13

El proyecto muestra como realizar una petición a un servicio REST,
para posteriormente manejar los eventos subsecuentes utilizando
`OperationQueue`, `Operation` y/o algún otro mecanismo.

Para ejecutar el proyecto simplemente descargue el repositorio y
ejecute el playground.

El core de este proyecto se encuentra en el archivo
link:./NetworkingWithOperation.playground/Contents.swift[Contents.swift]

image::cover.png[]

[source,swift]
----
// MARK:- Fetching information with NSOperations
let queue = OperationQueue()
// We will be using main operation Queue to update UI Components
let mainQueue = OperationQueue.main

var myImage: UIImage?
var metadata: ImageMetadata?

let operationForImage = BlockOperation(block: {
print("Started image download")
myImage = downloadImage(imageNumber: 1)
print("Finished image download")
})

let operationForMetadata = BlockOperation(block: {
print("Started download metadata")
metadata = downloadMetadata(imageNumber: 1)
print("Finished download metadata")
})

queue.addOperation(operationForImage)
queue.addOperation(operationForMetadata)
----