Skip to content

Instantly share code, notes, and snippets.

Avatar
🌐
Woohoooo 12k on SO!

Andrew Zheng aheze

🌐
Woohoooo 12k on SO!
View GitHub Profile
View SampleStoryFormat.txt
title: Sample story format
description: The story description goes here
author: Your name here!
image: https://getfind.app/image.png
emoji: 😀
date: 08/31/21
> *The code for this story is at https://gist.github.com/aheze/4997b82828718e05ea3ec20f3902dd57*.
> Hello! Lines starting with `>` are sent by Findbot.
! Hi! Lines starting with `!` are sent by Guide.
> Each message is 1 line. If you want more lines, use `<n>` for a newline.
@aheze
aheze / Make whole row clickable SwiftUI.swift
Created Aug 25, 2021
Demo code for "SwiftUI on macOS, how can I make the whole row clickable?"
View Make whole row clickable SwiftUI.swift
struct ContentView: View {
@State var selectedSite: String?
let sites = ["Gmail", "Apple", "Google"]
var body: some View {
List {
ForEach(sites, id: \.self) { site in
Button(action: {
self.selectedSite = site
}) {
View DefaultInfoPlist_Xcode13
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleIdentifier</key>
<string>com.YourName.YourAppName</string>
<key>CFBundleVersion</key>
<string>1</string>
View CallAttributedString.swift
/// Text("Output goes here!") <-- delete this
Text(getAttributedString(markdownText)) /// <-- replace with this
View GetAttributedString.swift
func getAttributedString(_ markdown: String) -> AttributedString {
do {
let attributedString = try AttributedString(markdown: markdown)
return attributedString
} catch {
print("Couldn't parse: \(error)")
}
return AttributedString("Error parsing markdown")
}
View BasicMarkdownUI.swift
struct ContentView: View {
@State var markdownText = ""
var body: some View {
HStack {
VStack {
Text("Markdown")
.fontWeight(.bold)
TextEditor(text: $markdownText)
View Attributes_SwiftUI.swift
struct ContentView: View {
var body: some View {
VStack(spacing: 40) {
/// Note: You can replace `$0` with `string in string`
VStack {
Text("Regular")
Text("Italics") { $0.font = Font.system(size: 17).italic() }
Text("Bold") { $0.font = Font.system(size: 17).bold() }
View ExtensionRangedAttributedString_SwiftUI.swift
struct ContentView: View {
var body: some View {
Text("Some Attributed String") { string in
string.foregroundColor = .blue
if let range = string.range(of: "Attributed") {
string[range].foregroundColor = .red
}
}
}
}
View RangedAttributedString_SwiftUI.swift
struct ContentView: View {
var body: some View {
Text(makeAttributedString())
}
func makeAttributedString() -> AttributedString {
var string = AttributedString("Some Attributed String")
string.foregroundColor = .blue
if let range = string.range(of: "Attributed") { /// here!
View BasicAttributedString_SwiftUI.swift
struct ContentView: View {
var body: some View {
Text(makeAttributedString())
}
func makeAttributedString() -> AttributedString {
var string = AttributedString("Some Attributed String")
string.foregroundColor = .blue
return string
}