Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Rita popcornomnom

:octocat:
View GitHub Profile
View NSClipViewExtension.swift
import Cocoa
extension NSClipView {
open override var isFlipped: Bool {
return true
}
}
View ___FILEBASENAME___.swift
//
// ___FILENAME___
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright (c) ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved.
//
// This file was generated by http://www.popcornomnom.com
//
View Localizable.string
//"<key>" = "<localized value>";
"welcomeTitle" = "Welcome!";
"start" = "Start";
View InAppEnum.swift
enum InApp: String, LocalizableDelegate {
case title = "inAppTitle"
case subtitle = "inAppSubtitle"
case description = "inAppDescription"
var table: String? {
return "InApps"
}
}
View LocalizableDelegate.swift
protocol LocalizableDelegate {
var rawValue: String { get } //localize key
var table: String? { get }
var localized: String { get }
}
extension LocalizableDelegate {
//returns a localized value by specified key located in the specified table
var localized: String {
return Bundle.main.localizedString(forKey: rawValue, value: nil, table: table)
View LocalizableUsage.swift
title.text = Localizable.WelcomePage.title.localized // Welcome!
View LocalizableDelegateUpgrated.swift
enum WelcomePage: String, LocalizableDelegate {
case title = "welcomeTitle"
case ctaButtonTitle = "start"
case next
}
View WelcomePageRaw.swift
enum WelcomePage: String {
case title
case ctaButtonTitle
}
View NSLocalizedString.swift
let welcomeText = NSLocalizedString("welcomeTitle", comment: "")
print(welcomeText) // Welcome!
View StopwatchTutorial1.swift
private let step: Double = 1.0 //1 second
private var timer: Timer?
//MARK: Timer lifecycle
private func initTimer() {
let action: (Timer)->Void = { [weak self] timer in
guard let strongSelf = self else {
return