Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kayoslab's full-sized avatar
:electron:
Focusing

Simon C. Krüger kayoslab

:electron:
Focusing
View GitHub Profile
@kayoslab
kayoslab / CLLocationCoordinate2D+Range.swift
Last active March 4, 2017 19:51
CLLocationCoordinate2D Extension to get a CoordinateRange struct within a given maximum Distance in Swift 3.0
/*
* Copyright (C) kayoslabs - All Rights Reserved
* Description from Jan Philip Matuschek
* (http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates)
* Written by kayoslabs, March 2017
*/
import Foundation
import MapKit
@kayoslab
kayoslab / TableViewController+Sort.swift
Last active May 31, 2021 17:59
Reorder UITableViewCells and modify the underlying CoreData Model
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
navigationItem.rightBarButtonItem = editButtonItem
}
@kayoslab
kayoslab / QueueHandler.swift
Created September 5, 2017 14:44
A simple Generic Queue with different priority Levels
import Foundation
/// Different Priority Levels for Queue Objects
public enum QueuePriority: Int {
case low = 0
case medium = 1
case high = 2
/// Returns the priority Type for using the main Queue.
fileprivate static func mainQueuePriority() -> QueuePriority {
@kayoslab
kayoslab / Logging.swift
Last active September 7, 2017 14:44
Quick test case implementation of a logging manager
class Logging {
/// An Enum that describes the actual Level on which
/// Messages should be logged to the console.
public enum Level: Int {
/// Log all messages.
case verbose = 0
/// Log messages of information level and higher.
case information = 1
/// Log messages of warning level and higher.
case warning = 2
@kayoslab
kayoslab / NotificationService.swift
Created July 26, 2018 13:53
Example implementation for a basic iOS 10 UNNotificationServiceExtension to handle jpg/gif/png files
import UserNotifications
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
@kayoslab
kayoslab / LegacyAlipayOrder.swift
Created September 18, 2018 09:14
Swift port of the Legacy Alipay Order, which is usually only available in Objective-C. I rely on the RSA implementation of SwiftyRSA here, so that I don't have to work with their own (obj-c) implementations.
import Foundation
import SwiftyRSA
/// Swift port of the always included _Order_ class from Alipay, because we suffered from the terrible code.
/// The code comments went through google translate to give us some hints on what is happening under the hood.
/// This struct is used to hold the data for an order within the alipay framework and to get the url parameter
/// containing the order object including a RSA signature.
private struct LegacyAlipayOrder {
/********************************** Pay four elements **********************************/
/// When the merchant signs an agreement with Alipay, Alipay assigns a unique
@kayoslab
kayoslab / AlipayOrder.swift
Last active September 19, 2018 12:37
Swift port according to the documentation on the Alipay website. I should create an example project for this in the future. As already mentioned in the legacy version of this class I'm relying on SwiftyRSA for the signing here.
import Foundation
import SwiftyRSA
/// Automatically generated by the Chinese Website.
struct AlipayPublicParameter {
enum CodingKeys: String, CodingKey {
case appID = "app_id"
case method
case format
case charset
@kayoslab
kayoslab / swiftlint.yml
Created July 8, 2020 05:54
Default configuration for SwiftLint. This is the standard configuration I use in most of my projects.
### Global configuration
# Enable rules which are not in the default set
opt_in_rules:
# - anyobject_protocol # Prefer using `AnyObject` over `class` for class-only protocols.
# - array_init # Prefer using `Array(seq)` over `seq.map { $0 }` to convert a sequence into an Array.
# - attributes # Attributes should be on their own lines in functions and types, but on the same line as variables and imports.
- block_based_kvo # Prefer the new block based KVO API with keypaths when using Swift 3.2 or later.
- class_delegate_protocol # Delegate protocols should be class-only so they can be weakly referenced.
- closing_brace # Closing brace with closing parenthesis should not have any whitespaces in the middle.
@kayoslab
kayoslab / .gitignore
Created July 8, 2020 06:01
A useful .gitignore file for iOS development
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
@kayoslab
kayoslab / UIView+nib.swift
Last active July 8, 2020 07:52
A UIView extension to make it easier working with nib and code layouts at the same time. This usually is present in every project I'm working on the interface.
import UIKit
/// A UIView extension to make it easier working with nib and code layouts at the same time.
public extension UIView {
/// Unarchives the contents of a nib file.
///
/// - Returns: The top-level objects in the nib file.
class func fromNib<T: UIView>() -> T {
return Bundle(for: T.self).loadNibNamed(