Skip to content

Instantly share code, notes, and snippets.

View artemnovichkov's full-sized avatar
👨‍💻
Write code. Blow minds.

Artem Novichkov artemnovichkov

👨‍💻
Write code. Blow minds.
View GitHub Profile
guard let enumerator = FileManager.default.enumerator(at: projectURL, includingPropertiesForKeys: nil) else {
exit(1)
}
var swiftFileURLs = enumerator.allObjects
.compactMap { $0 as? URL }
.filter { $0.pathExtension == "swift" }
import Foundation
// Get project URL
guard let projectDirRawValue = getenv("PROJECT_DIR"),
let projectDirectoryPath = String(utf8String: projectDirRawValue) else {
exit(1)
}
let projectURL = URL(fileURLWithPath: projectDirectoryPath)
// Get Info.plist path
guard let productSettingsPathRawValue = getenv("PRODUCT_SETTINGS_PATH"),
@artemnovichkov
artemnovichkov / Optional+Operators.swift
Last active July 30, 2018 15:16
Addition and subtraction operators for Swift Optionals
func +=<T>(lhs: inout T?, rhs: T) where T: SignedNumeric {
switch lhs {
case .none:
break
case .some(let value):
lhs = .some(value + rhs)
}
}
func -=<T>(lhs: inout T?, rhs: T) where T: SignedNumeric {
@artemnovichkov
artemnovichkov / Quick-Start.swift
Created November 26, 2017 06:26
Good brief example of README installation section from here: https://github.com/NextLevel/NextLevel#quick-start
# CocoaPods
swift_version = "4.0"
pod "NextLevel", "~> 0.9.0"
# Carthage
github "nextlevel/NextLevel" ~> 0.9.0
# Swift PM
let package = Package(
dependencies: [
@artemnovichkov
artemnovichkov / AppStore.swift
Created October 31, 2017 02:33
Open App Store for review
func openAppStore() {
let appID = 1227356223
let appURLString: String
if #available(iOS 11.0, *) {
appURLString = "itms-apps://itunes.apple.com/us/app/itunes-u/id\(appID)?action=write-review"
}
else {
appURLString = "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=\(appID)"
}
UIApplication.shared.openURL(URL(string: appURLString)!)
@artemnovichkov
artemnovichkov / Package.swift
Created September 20, 2017 02:51
Template for Swift Package Manager Manifest
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "Sasha",
dependencies: [
.package(url: "https://github.com/artemnovichkov/carting.git", from: "1.0.0"),
],
targets: [
@artemnovichkov
artemnovichkov / ServicesComposition.swift
Last active May 4, 2018 07:17
Using protocol composition and generics for dependency injection in Interactors (VIPER, SOA, another cool keywords...)
//Inspired by: http://merowing.info/2017/04/using-protocol-compositon-for-dependency-injection/
//Protocols for objects owning services. Interactors in VIPER, for example.
protocol HasLogService {
var logService: LogService { get }
}
protocol HasLoginService {
var loginService: LoginService { get }
}
@artemnovichkov
artemnovichkov / KeyboardNotificationObserver.swift
Last active May 10, 2018 05:19
Simple protocol for sugar keyboard notification observing
protocol KeyboardNotificationObserver {
typealias Selectors = (show: Selector, hide: Selector)
func addKeyboardWillChangeObservers(with selectors: Selectors)
func removeKeyboardWillChangeObservers()
func addKeyboardDidChangeObservers(with selectors: Selectors)
func removeKeyboardDidChangeObservers()
}
@artemnovichkov
artemnovichkov / .swiftlint.yml
Created January 30, 2017 02:09
Configuration file for SwiftLint
disabled_rules:
- trailing_whitespace
excluded:
- Carthage/
force_try: warning
force_cast: warning
line_length: 180
colon:
apply_to_dictionaries: false
@artemnovichkov
artemnovichkov / NSViewController+Loading.swift
Created January 26, 2017 07:26
NSViewController category for simple initialization from storyboard/nib.
import AppKit
extension NSViewController {
static func load<T>() -> T where T: NSViewController {
return T(nibName: T.className(), bundle: nil)!
}
}
//Usage:
//let viewController: LoginViewController = .load()