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
// Source: https://noahgilmore.com/blog/swiftui-two-columns-equal-width/ | |
struct ContentView: View { | |
var body: some View { | |
HStack(alignment: .top, spacing: 0) { | |
Rectangle() | |
.fill(Color.blue) | |
.frame(minWidth: 0, maxWidth: .infinity) | |
Rectangle() | |
.fill(Color.red) |
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
/* | |
Scenario: Sometimes you want the entire background color to be filled in your SwiftUI | |
- One solution is to make the color `edgesIgnoringSafeArea(.all)` | |
- This is not obvious but it seems to work for now | |
*/ | |
struct Example: View { | |
var body: some View { |
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
// 01 Example with struct | |
// Use ForEach to provide views based on a `RandomAccessCollection` of some data type. | |
// see documentation: https://developer.apple.com/documentation/swiftui/foreach | |
// I want the index you can do the following... | |
// You use `results.enumerated().map({$0}` which takes your results and returns it into an array | |
// I have seen examples where you could do it like `Array(results.enumerated())` | |
// NOTE: | |
// The collection’s elements must conform to Identifiable or you need to provide an id parameter to the ForEach initializer. |
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
// Example A | |
// This example it works fine because `id:\.0` is an Int and is unique | |
struct Example: View { | |
var tupleListExample: [(Int, String)] = [ | |
(1, "A"), | |
(2, "B"), | |
(3, "C"), |
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 | |
import Combine | |
// 01 Enum | |
enum Activesheet: Identifiable { | |
case twitter | |
case picker | |
case web | |
var id: String { |
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
// Original Tweet: https://twitter.com/Al_Grigor/status/1357028887209902088 | |
// input : "aaaabbbcca" | |
// output: [("a", 4), ("b", 3), ("c", 2), ("a", 1)] | |
func splitter(str: String) -> [(String, Int)] { | |
// 01 This will give you an Array of letters | |
let letters = str.map { String($0) } |
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
// On Intial Render | |
init() { | |
this._super(...arguments); | |
console.log('init'); | |
}, | |
didReceiveAttrs() { | |
this._super(...arguments); | |
console.log('didReceiveAttrs'); | |
}, |
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
# ------------------------------------------------------------ | |
# The Toto Archive page has a collection called 'archive' | |
# We use Ruby's group_by method to enumerate over the collection by :year | |
# And then iterate through the posts | |
# ------------------------------------------------------------ | |
<% archives.group_by { | archive | archive[:date].year }.each do | year, posts | %> | |
<%= year %> | |
<% for post in posts %> | |
<a href="<%= post.path %>"><%= post.title %></a> |