Skip to content

Instantly share code, notes, and snippets.

View novinfard's full-sized avatar

Soheil Novinfard novinfard

View GitHub Profile
@novinfard
novinfard / EntityRequest-MCT.swift
Last active March 16, 2020 12:21
[Entity Request - MCT Article]
protocol EntityRequest {
var entityName: String { get }
var predicate: NSPredicate? { get }
}
@novinfard
novinfard / StandingsNetworkRequest_MCT.swift
Created March 4, 2020 12:27
[Standing Network Request - MCT article]
class StandingsNetworkRequest: StandingsEndpointRequest {
let tournamentId: Int32
init(tournamentId: Int32){
self.tournamentId = tournamentId
}
func url() -> String {
return "https://service-url/getStandings?tournamentId=\(tournamentId)"
}
@novinfard
novinfard / StandingsEndpointRequest_MCT.swift
Created March 4, 2020 12:06
[Standings Endpoint Request - MCT Article]
protocol StandingsEndpointRequest: RequestProtocol {
var tournamentId: Int32 { get }
}
extension StandingsEndpointRequest {
func parser(parseDelegate: ParseDelegate, parentContext: NSManagedObjectContext)
-> ParseOperation {
return StandingsParser(delegate: parseDelegate, parentContext: parentContext)
}
}
@novinfard
novinfard / StandingsDatasource-constructor-injection-MCT.swift
Created March 3, 2020 22:19
[Constructor Injection - MCT article]
class StandingsDatasource: ManagedDataSource {
let request: StandingsRequest
...
init(request: StandingsRequest, ...) {
self.request = request
...
}
@novinfard
novinfard / StandingsDatasource-parameter-injection-MCT.swift
Created March 3, 2020 15:01
[Parameter Injection - MCT article]
class StandingsDatasource: ManagedDataSource {
var request: StandingsRequest?
...
override func requestData() {
guard request = self.request else {
assertionFailure("Request is not initiated in StandingsDatasource")
return
}
@novinfard
novinfard / StandingsRequest_v1.swift
Created February 18, 2020 18:47
[Standing request v1 - MCT article]
class StandingsRequest: RequestProtocol {
let tournamentId: Int32
init(tournamentId: Int32){
self.tournamentId = tournamentId
}
func url() -> String {
return "https://service-url/getStandings?tournamentId=\(tournamentId)"
}
@novinfard
novinfard / standing_data_object.swift
Created February 18, 2020 18:35
[Standing data object - MCT article]
public class Standing: NSManagedObject {
@NSManaged public var tournamentId: Int32
@NSManaged public var title: String
@NSManaged public var content: String
@NSManaged public var groupName: String
}
// MARK: - Preidcates
public extension Standing {
static func predicateWith(groupName: String?) -> NSPredicate? {
@novinfard
novinfard / standingDatasource_v1.swift
Last active February 18, 2020 18:22
[Standing Datasource v1 - MCT article]
class StandingsDatasource: ManagedDataSource {
let tournamentId: Int32
let groupName: String?
let dataController: RequestDataConnectionController
init(tournamentId: Int32,
groupName: String?,
managedObjectContext: NSManagedObjectContext,
@novinfard
novinfard / round-corner-view.swift
Last active February 5, 2020 20:09
[Rounding and masking the corners of UIView]
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.contentView?.maskAndRoundCorners(corners: [.topRight, .topLeft], radius: 8)
}
extension UIView {
/// Masking and rounding the view corners
///
/// NOTE: should be used in viewDidLayoutSubviews as it manipulates the layers
@novinfard
novinfard / unit-test-reading-to-storing-utcd.swift
Last active January 29, 2020 17:14
[Unit Test - Reading to Storing: complete solution - UTCD]
import XCTest
import CoreData
@testable import MyApp
class NewsTests: CoreDataBaseTest {
private let jsonFile = "news_today"
func testReadingJsonFiles() {
let dataDict = self.getJsonDictionaryFromFile(self.jsonFile)