Skip to content

Instantly share code, notes, and snippets.

View DenTelezhkin's full-sized avatar

Denys Telezhkin DenTelezhkin

View GitHub Profile
@DenTelezhkin
DenTelezhkin / StateWrappedView.swift
Created September 23, 2020 14:01
StateObject alternative on iOS 13 / macOS Catalina
import SwiftUI
protocol ViewModelContainable: View {
associatedtype ViewModel : ObservableObject
init(model: ViewModel)
}
// This struct is a direct MVVM alternative to @StateObject in iOS 14 and Mac OS Big Sur.
@DenTelezhkin
DenTelezhkin / SwiftUI code generation template for SwiftGen.md
Last active April 29, 2022 07:36
SwiftUI code generation template for SwiftGen

Example of generated code

internal extension Color {
  // Assets.xcassets
  static var midnightBlue : Color { Color("midnightBlue", bundle: BundleToken.bundle) }
}

internal extension Image {
// Assets.xcassets
@DenTelezhkin
DenTelezhkin / StackViewExample.swift
Created March 27, 2019 10:36
StackView example for MLSDev blog article
let stacks = [UserProfileStatsView(), SwitchCompanyView(), SendInvitationToCompanyView(), LogoutButtonView()]
stackView.axis = .Vertical
stacks.forEach {
stackView.addArrangedSubview($0)
}
@DenTelezhkin
DenTelezhkin / LoadableFromXibView.swift
Created March 27, 2019 10:35
LoadableFromXibView example for MLSDev blog article.
protocol NibDefinable {
var nibName: String { get }
}
extension NibDefinable {
var nibName : String {
return String(self.dynamicType)
}
}
@DenTelezhkin
DenTelezhkin / UIView+extensions.swift
Created March 27, 2019 10:34
IBInspectable example for MLSDev blog articles
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get { return layer.cornerRadius }
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
@IBInspectable var borderWidth: CGFloat {
@DenTelezhkin
DenTelezhkin / Fastfile
Created March 27, 2019 10:33
Fastfile example for MLSDev blog article.
before_all do
cocoapods
scan
end
# Increment build number to current date
lane :set_build_number do
increment_build_number(
build_number: Time.new.strftime("%Y.%m.%d.%H%M")
)
@DenTelezhkin
DenTelezhkin / MeasureAppStartupTime.swift
Last active May 21, 2024 13:40
Measure iOS app startup time, in seconds, from the time user tapped an icon on the home screen (using time, when app process was created). Swift 4.
// Returns number of seconds passed between time when process was created and function was called
func measureAppStartUpTime() -> Double {
var kinfo = kinfo_proc()
var size = MemoryLayout<kinfo_proc>.stride
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
sysctl(&mib, u_int(mib.count), &kinfo, &size, nil, 0)
let start_time = kinfo.kp_proc.p_starttime
var time : timeval = timeval(tv_sec: 0, tv_usec: 0)
gettimeofday(&time, nil)
let currentTimeMilliseconds = Double(Int64(time.tv_sec) * 1000) + Double(time.tv_usec) / 1000.0
@DenTelezhkin
DenTelezhkin / prepare_icons.sh
Created September 30, 2016 07:56
Slice iOS app icons from 1024x1024 PNG file, originally taken from https://gist.github.com/jessedc/837916#file-ios-icon-png-bash-script. Updated for Xcode 8 - September 2016.
#!/bin/bash
f=$(pwd)
sips --resampleWidth 512 "${f}/${1}" --out "${f}/iTunesArtwork"
sips --resampleWidth 1024 "${f}/${1}" --out "${f}/iTunesArtwork@2x"
sips --resampleWidth 20 "${f}/${1}" --out "${f}/Icon-20.png"
sips --resampleWidth 40 "${f}/${1}" --out "${f}/[email protected]"
sips --resampleWidth 60 "${f}/${1}" --out "${f}/[email protected]"
@DenTelezhkin
DenTelezhkin / LoadableFromXibView.swift
Last active July 4, 2020 17:47
DEPRECATED. Please use https://github.com/MLSDev/LoadableViews. Create reusable views in XIBs and easily load them in another XIB, storyboard, or programmatically.
import Foundation
import UIKit
protocol NibDefinable {
var nibName: String { get }
}
extension NibDefinable {
var nibName : String {
return String(self.dynamicType)
@DenTelezhkin
DenTelezhkin / README.md
Last active December 8, 2016 10:08
Rakefile for iTunesConnect upload and testing, iOS

What's this stuff about?

This is a build script for installing dependencies, running tests, and uploading your iOS application builds to Apple's iTunesConnect & Testflight.

Used technologies

  • CocoaPods
  • XCTest
  • Ruby gems: xcpretty, deliver, shenzhen
  • Apple's iTunesConnect&Testflight