Skip to content

Instantly share code, notes, and snippets.

@DenTelezhkin
DenTelezhkin / StateWrappedView.swift
Created Sep 23, 2020
StateObject alternative on iOS 13 / macOS Catalina
View StateWrappedView.swift
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 Nov 18, 2020
SwiftUI code generation template for SwiftGen
View SwiftUI code generation template for SwiftGen.md

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 Mar 27, 2019
StackView example for MLSDev blog article
View StackViewExample.swift
let stacks = [UserProfileStatsView(), SwitchCompanyView(), SendInvitationToCompanyView(), LogoutButtonView()]
stackView.axis = .Vertical
stacks.forEach {
stackView.addArrangedSubview($0)
}
@DenTelezhkin
DenTelezhkin / LoadableFromXibView.swift
Created Mar 27, 2019
LoadableFromXibView example for MLSDev blog article.
View LoadableFromXibView.swift
protocol NibDefinable {
var nibName: String { get }
}
extension NibDefinable {
var nibName : String {
return String(self.dynamicType)
}
}
@DenTelezhkin
DenTelezhkin / UIView+extensions.swift
Created Mar 27, 2019
IBInspectable example for MLSDev blog articles
View UIView+extensions.swift
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 Mar 27, 2019
Fastfile example for MLSDev blog article.
View Fastfile
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 Apr 21, 2021
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.
View MeasureAppStartupTime.swift
// 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 Sep 30, 2016
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.
View prepare_icons.sh
#!/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}/Icon-20@2x.png"
sips --resampleWidth 60 "${f}/${1}" --out "${f}/Icon-20@3x.png"
@DenTelezhkin
DenTelezhkin / LoadableFromXibView.swift
Last active Jul 4, 2020
DEPRECATED. Please use https://github.com/MLSDev/LoadableViews. Create reusable views in XIBs and easily load them in another XIB, storyboard, or programmatically.
View LoadableFromXibView.swift
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 Dec 8, 2016
Rakefile for iTunesConnect upload and testing, iOS
View README.md

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