Skip to content

Instantly share code, notes, and snippets.

Avatar
👇
avanderlee.com

Antoine van der Lee AvdLee

👇
avanderlee.com
View GitHub Profile
View MappingImplementation.swift
class Content: NSManagedObject {
// MARK: - Mappable
func mapValues(using mapper: Mapping) throws {
let mapper = try mapper.mapper(for: self, destination: CKContent.self)
mapper.map(\.objectID, \.identifier, transform: { objectID -> String in
return objectID.uriRepresentation().absoluteString
})
mapper.map(\.name, \.name)
mapper.map(\.url, \.url)
mapper.map(\.downloadURLExpiry, \.downloadURLExpiry)
View Mappable.swift
//
// ContentMapper.swift
//
//
// Created by Antoine van der Lee on 09/03/2021.
//
import Foundation
import ContentKit
@AvdLee
AvdLee / ContentMapping.swift
Last active Mar 9, 2021
Mapping from Core Data to a class and reversed
View ContentMapping.swift
import Cocoa
open class Content: Mappable {
var name: String = ""
init(name: String = "") {
self.name = name
}
func mapValues(using mapper: Mapping) throws {
@AvdLee
AvdLee / IssuesCountQualityCheck.swift
Created Apr 10, 2020
A quality check for a repository issues count
View IssuesCountQualityCheck.swift
struct IssuesCountQualityCheck: RepositoryQualityCheck {
let id: String = UUID().uuidString
let title = "Issues count"
let score: Int
init(repository: Repository) {
switch repository.issuesCount {
case 0..<10:
score = 100
case 10..<20:
@AvdLee
AvdLee / FileManagerExtensions.swift
Last active Sep 3, 2021
Easily print out useful locations for usage during debugging on the Simulator.
View FileManagerExtensions.swift
extension FileManager {
/*
Prints out the locations of the simulator and the shared group folder.
This is useful for debugging file issues.
Example usage: FileManager.default.printFileLocations()
*/
func printFileLocations() {
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let simulatorFolder = paths.last!
@AvdLee
AvdLee / DarwinNotificationCenter.swift
Last active Jul 29, 2021
A notification center for Darwin Notifications. MIT License applies.
View DarwinNotificationCenter.swift
//
// DarwinNotificationCenter.swift
//
// Copyright © 2017 WeTransfer. All rights reserved.
//
import Foundation
/// A Darwin notification payload. It does not contain any userInfo, a Darwin notification is purely event handling.
public struct DarwinNotification {
@AvdLee
AvdLee / largest-file.sh
Last active Sep 9, 2019
Find your project's Swift file with the most lines of code
View largest-file.sh
find . -type f -name "*.swift" -exec grep -H -c '[^[:space:]]' {} \; | \sort -nr -t":" -k2 | awk -F: '{printf("Your largest file %s contains: %s lines \n", $1, $2); exit;}'
@AvdLee
AvdLee / Flattener Playground
Created Aug 7, 2019
A Flattener written in Swift
View Flattener Playground
/// - We have multiple files with a X amount of chunks
/// - Each batch request can contain a max of 50 chunks from possibly multiple files
///
/// Challenge: Distribute the chunk requests over as less batch requests as possible
import UIKit
import Foundation
typealias PublicIdentifier = String
View Performance in Swift.csv
Type of code Xcode Unit Test Playground Terminal
For loop if 0.026 26.052 0.030
Filter forEach 0.043 2.116 0.047
@AvdLee
AvdLee / ForPerformance.playground
Created Oct 4, 2018
For each vs for loop performance
View ForPerformance.playground
//: Playground - noun: a place where people can play
import XCTest
class MyTests: XCTestCase {
lazy var testData: [Int] = {
return (0..<1000).map { Int($0) }
}()