Skip to content

Instantly share code, notes, and snippets.

struct MyModelDTO {
let property1: Type1
let property2: Type2
}
extension MyModelDTO {
init(model: MyModel_CoreData) {
self.init(property1: model.property1, property2: model.property2)
}
}
@JohnSundell
JohnSundell / OnboardingManager.swift
Last active May 21, 2020 08:19
An example of using #function for user defaults properties, and a test that guards against property name changes
import UIKit
class OnboardingManager {
private let userDefaults: UserDefaults
init(userDefaults: UserDefaults = .standard) {
self.userDefaults = userDefaults
}
func presentOnboardingControllerIfNeeded(in viewController: UIViewController) {
@paulsturgess
paulsturgess / service.js
Last active August 8, 2024 04:25
An example Service class wrapper for Axios
import axios from 'axios';
class Service {
constructor() {
let service = axios.create({
headers: {csrf: 'token'}
});
service.interceptors.response.use(this.handleSuccess, this.handleError);
this.service = service;
}
@shagunsodhani
shagunsodhani / SmartReply.md
Last active October 22, 2022 12:29
Notes for "Smart Reply: Automated Response Suggestion for Email" Paper

Smart Reply: Automated Response Suggestion for Email

Introduction

  • Proposes a novel, end-to-end architecture for generating short email responses.
  • Single most important benchmark of its success is that it is deployed in Inbox by Gmail and assists with around 10% of all mobile responses.
  • Link to the paper.

Challenges in deploying Smart Reply in a user-facing product

@ole
ole / CharacterArray.swift
Last active June 11, 2023 10:13
Two options for converting character ranges into arrays
// We can't use `Character` or `String` ranges directly because they aren't countable
// Create a countable range of ASCII values instead
let range = UInt8(ascii: "a")...UInt8(ascii: "z") // CountableClosedRange<UInt8>
// Convert ASCII codes into Character values
range.map { Character(UnicodeScalar($0)) } // Array<Character>
// → ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
@rkawajiri
rkawajiri / ProvisioningProfile.swift
Last active May 30, 2017 14:15 — forked from steipete/DevelopmentEnviromentDetector.m
Detect if you're currently running a development version or an App Store/Ad Hoc version (Re-implemented in Swift)
public struct ProvisioningProfile {
public static let sharedInstance = ProvisioningProfile()
#if (arch(i386) || arch(x86_64)) && os(iOS)
public let isDevelopment = true
#else
public let isDevelopment: Bool
private init() {
guard let provision = NSBundle.mainBundle().pathForResource("embedded", ofType: "mobileprovision"),
let data = NSData(contentsOfFile: provision) else {
isDevelopment = false
@austinzheng
austinzheng / swiftDelegateExample.swift
Created August 1, 2015 00:12
A simple example of setting up a delegate in Swift.
//
// ExampleCode.swift
//
import UIKit
// MARK: - Protocol
protocol SearchQueryProviderProtocol : class { // 'class' means only class types can implement it
func searchQueryData() -> String
@JaviLorbada
JaviLorbada / FRP iOS Learning resources.md
Last active July 11, 2025 21:46
The best FRP iOS resources.

Videos

@kevin-smets
kevin-smets / iterm2-solarized.md
Last active July 16, 2025 04:34
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@steipete
steipete / DevelopmentEnviromentDetector.m
Last active February 7, 2025 15:27
Detect if you're currently running a development version or an App Store/Ad Hoc version.
static BOOL PSPDFIsDevelopmentBuild(void) {
#if TARGET_IPHONE_SIMULATOR
return YES;
#else
static BOOL isDevelopment = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// There is no provisioning profile in AppStore Apps.
NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
if (data) {