Skip to content

Instantly share code, notes, and snippets.

@arpitdsoni
arpitdsoni / WaitView.swift
Created August 20, 2017 04:13
Playing with custom UIView
// WaitView.swift
//
// Created by Arpit Soni on 8/20/17.
// Copyright © 2017 Arpit Soni. All rights reserved.
import UIKit
import PlaygroundSupport
let viewFrame = CGRect(x: 0, y: 0, width: 500, height: 500)
let view = UIView(frame: viewFrame)
@arpitdsoni
arpitdsoni / add_lprojs.rb
Last active January 6, 2019 02:03
Adding lproj folder reference in xcodeproj
require 'xcodeproj'
require 'dotenv'
# Dotenv.load('.env.lprojs')
localizations = ENV['LOCALIZATIONS'].split(',')
puts "Localizations: " + localizations.inspect
project = Xcodeproj::Project.open('LocalizationPrototype.xcodeproj')
target = project.targets.first
parent_group = project.groups.first
@arpitdsoni
arpitdsoni / OptionSetStringIntializing.swift
Created July 2, 2019 02:54
Create OptionSet from JSON in Swift
public protocol OptionSetStringIntializing {
init?(_ stringValue: String)
}
public extension OptionSet {
static func decode<T>(from strings: [String]) -> T where T: OptionSet, T: OptionSetStringIntializing {
var options: T = []
strings.forEach { (str) in
@arpitdsoni
arpitdsoni / get_devices_dev_profile.rb
Created October 24, 2019 21:43
Save all devices for a dev provisioning profile using fastlane
desc "Save all devices for a dev provisioning profile to devices.txt"
lane :get_devices_dev_profile do
require "spaceship"
Spaceship::Portal.login()
bundle_id = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier).first
profile = Spaceship::Portal.provisioning_profile.development.find_by_bundle_id(bundle_id: bundle_id).first
devices = profile.devices
File.open('devices.txt', 'w') do |f|
f.puts "Device ID\tDevice Name"
devices.each do |device|
@arpitdsoni
arpitdsoni / fastlane_build_bump.rb
Created November 9, 2019 12:26
develop branch as source of truth
desc "Gets the build number from develop, returns incremented number"
lane :incremented_build_number do
# the truth for the current build number is on develop, switch branch and get the number
orig_git_branch = git_branch
sh("git checkout develop")
build_number = get_build_number.to_i + 1
sh("git checkout #{orig_git_branch}")
build_number
end
import UIKit
class HyperlinkLabel: UILabel {
var stringAndUrl: [String: URL] = [:] {
didSet {
attributedText = attributedText()
}
}
protocol SafeValueForKeyPath {}
extension SafeValueForKeyPath where Self: CFXManagedObject {
func safeValueForKeyPath<Value>(_ keyPath: KeyPath<Self, Value?>) -> Value? {
let keyPathStr = NSExpression(forKeyPath: keyPath).keyPath
return managedObjectContext?.performAndWait {
return value(forKeyPath: keyPathStr) as? Value
}
}
}
@arpitdsoni
arpitdsoni / colors-swift5.stencil
Last active September 16, 2020 16:40
Modified SwiftGen xcassets template to make static constant of type UIColor or NSColor
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
{% if catalogs %}
{% set enumName %}{{param.enumName|default:"Colors"}}{% endset %}
{% set colorType %}{{param.colorTypeName|default:"Color"}}{% endset %}
{% set forceNamespaces %}{{param.forceProvidesNamespaces|default:"false"}}{% endset %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
#if os(macOS)
import AppKit
@arpitdsoni
arpitdsoni / images-swift5.stencil
Created September 16, 2020 16:37
Modified SwiftGen xcassets template for images. Makes static const of type UIImage or NSImage.
// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
{% if catalogs %}
{% set enumName %}{{param.enumName|default:"Images"}}{% endset %}
{% set enumNameForStrings %}{{param.enumNameForStrings|default:"ImageNames"}}{% endset %}
{% set imageType %}{{param.imageTypeName|default:"Image"}}{% endset %}
{% set forceNamespaces %}{{param.forceProvidesNamespaces|default:"false"}}{% endset %}
{% set accessModifier %}{% if param.publicAccess %}public{% else %}internal{% endif %}{% endset %}
#if os(macOS)
protocol HyperLinkTextViewDelegate: class {
func textView(textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool
}
/// converts text to attributedText with clickable strings
class HyperLinkTextView: UITextView, UITextViewDelegate {
weak var hyperLinkTextViewDelegate: HyperLinkTextViewDelegate?
var additionalAttributesForLinkText: [NSAttributedString.Key : Any] = [:]