Skip to content

Instantly share code, notes, and snippets.

View raphschwander's full-sized avatar

Raphael Neuenschwander raphschwander

View GitHub Profile
@raphschwander
raphschwander / String+emailAddresses
Created November 7, 2017 08:50
Get email addresses in a string, discard any other content
extension String {
/** Get email addresses in a string, discard any other content. */
func emailAddresses() -> [String] {
var addresses = [String]()
if let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) {
let matches = detector.matches(in: self, options: [], range: NSMakeRange(0, self.count))
for match in matches {
if let matchURL = match.url,
let matchURLComponents = URLComponents(url: matchURL, resolvingAgainstBaseURL: false),
matchURLComponents.scheme == "mailto"
@raphschwander
raphschwander / FlipView.swift
Last active December 15, 2022 07:24
Flip View - SwiftUI
// MARK: - Usage
struct ContentView: View {
@State private var isFlipped = false
var body: some View {
FlipView(duration: 0.75,
perspective: 0.5,
isFlipped: $isFlipped) {
Color.red
@raphschwander
raphschwander / View+frameRatio.swift
Created December 8, 2022 13:41
Set frame aspect ratio - SwiftUI
import SwiftUI
// MARK: - ReadSize
struct SizePreferenceKey: PreferenceKey {
static var defaultValue: CGSize = .zero
static func reduce(value: inout CGSize, nextValue: () -> CGSize) {}
}
extension View {
@raphschwander
raphschwander / ScratchCard.swift
Created December 15, 2022 10:03
ScratchCard - SwiftUI
import SwiftUI
// MARK: - Usage
struct ContentView: View {
@State var isRevealed: Bool = false
@State var scratchProgress: Double = 0
var body: some View {
VStack(spacing: 16) {