Skip to content

Instantly share code, notes, and snippets.

View rahul-inspired-iosdeveloper's full-sized avatar
🏠
Working from home

Rahul K Rajan rahul-inspired-iosdeveloper

🏠
Working from home
  • India
View GitHub Profile
import Foundation
struct BaseURL {
static let baseURL = "https://learnappmaking.com/"
}
struct AppAPI {
class LiveNewsInteractor: PresentorToInteractorProtocol{
var presenter: InteractorToPresenterProtocol?
func fetchLiveNews() {
Alamofire.request(Constants.URL).response { response in
if(response.response?.statusCode == 200){
guard let data = response.data else { return }
do {
let decoder = JSONDecoder()
import Foundation
import CoreData
protocol CoreDataManagerProtocol: class {
func didCartItemAdded() -> ()
}
class CoreDataManager {
let queue = OperationQueue()
queue.maxConcurrentOperationCount = 2
let operation1 = BlockOperation(block: {
let a = 5+1000
print(a)
})
operation1.qualityOfService = .userInitiated
let operation2 = BlockOperation(block: {
let privateMOC = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
privateMOC.parent = context
privateMOC.performAndWait {
//do some coredata stuff, but dont carry on beyond this block, until the code
//in this block has finished executed (sync, not async)
saveContext(forContext: privateMOC)
}
//now save the main context with the changes from the private context
saveContext(forContext: context)