This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let gifts = [ "partridge in a pear tree", "Two turtle doves", "Three French hens", | |
"Four calling birds", "Five golden rings", "Six geese a-laying", | |
"Seven swans a-swimming", "Eight maids a-milking", "Nine ladies dancing", | |
"Ten lords a-leaping", "Eleven pipers piping", "Twelve drummers drumming" ] | |
let nth = [ "first", "second", "third", "fourth", "fifth", "sixth", | |
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ] | |
func gifts(for day: Int) -> String { | |
var result = "On the \(nth[day-1]) day of Christmas, my true love sent to me:\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (resourceIsAvailable) { | |
resourceIsAvailable = false | |
useResource() | |
resourceIsAvailable = true | |
} else { | |
// resource is not available, wait or do something else | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
func load(image imageName: String) -> UIImage { | |
// declare image location | |
let imagePath: String = "\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/\(imageName).png" | |
let imageUrl: URL = URL(fileURLWithPath: imagePath) | |
// check if the image is stored already | |
if FileManager.default.fileExists(atPath: imagePath), | |
let imageData: Data = try? Data(contentsOf: imageUrl), | |
let image: UIImage = UIImage(data: imageData, scale: UIScreen.main.scale) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Throws error if ALL localizable files does not have matching keys | |
/// | |
/// - Parameter files: list of localizable files to validate | |
func validateMatchKeys(_ files: [LocalizationStringsFile]) { | |
print("------------ Validating keys match in all localizable files ------------") | |
guard let base = files.first, files.count > 1 else { return } | |
let files = Array(files.dropFirst()) | |
files.forEach { | |
guard let extraKey = Set(base.keys).symmetricDifference($0.keys).first else { return } | |
let incorrectFile = $0.keys.contains(extraKey) ? $0 : base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class MyView: UIView { | |
fileprivate var myPreviewInteraction: Any? = nil | |
init() { | |
super.init(frame: CGRect.zero) | |
if #available(iOS 10.0, *) { | |
myPreviewInteraction = UIPreviewInteraction(view: self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// System Colors Playground | |
// fivestars.blog | |
// | |
// Created by Federico Zanetello on 9/6/19. | |
// | |
import UIKit | |
import PlaygroundSupport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// System Materials Playground | |
// fivestars.blog | |
// | |
// Created by Federico Zanetello on 9/6/19. | |
// | |
import UIKit | |
import PlaygroundSupport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// System Colors Playground | |
// fivestars.blog | |
// | |
// Created by Federico Zanetello on 9/6/19. | |
// | |
import UIKit | |
import PlaygroundSupport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
class AppState: ObservableObject { | |
@Published var screenAState: Bool = false | |
@Published var screenBState: Bool = false | |
} | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var selection = 0 | |
private var actionSelection: Binding<Int> { | |
Binding<Int>(get: { | |
self.selection | |
}) { (newValue: Int) in | |
if newValue == 1 { | |
// put action here |