Skip to content

Instantly share code, notes, and snippets.


Alen Mujkic alenm

View GitHub Profile
alenm / twocolumns.swift
Last active Mar 18, 2021
Equal Width Two Column SwiftUI
View twocolumns.swift
// Source:
struct ContentView: View {
var body: some View {
HStack(alignment: .top, spacing: 0) {
.frame(minWidth: 0, maxWidth: .infinity)
alenm / SettingBackgroundColor.swift
Created Mar 2, 2021
Setting background color when top edge is white
View SettingBackgroundColor.swift
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 {
alenm / ForEachEnumerated.swift
Created Feb 23, 2021
ForEach and with an index using SwiftUI
View ForEachEnumerated.swift
// 01 Example with struct
// Use ForEach to provide views based on a `RandomAccessCollection` of some data type.
// see documentation:
// 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.
alenm / ForEachArrayOfTupleExample.swift
Created Feb 14, 2021
ForEach over an Array of Tuples. Note in order for this to work properly you need to have some unique id. In this example that is in the Integer. If it's not unique you will run into issues
View ForEachArrayOfTupleExample.swift
// 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"),
alenm / multipleSheetsInSwiftUI.swift
Last active Apr 15, 2021
Having multiple sheets within one SwiftUI view can happen. The `sheet(item:content:)` takes an item: Binding<Identifiable> which means in the latest swift you can use an Enum and switch on it in the content closure.
View multipleSheetsInSwiftUI.swift
import SwiftUI
import Combine
// 01 Enum
enum Activesheet: Identifiable {
case twitter
case picker
case web
var id: String {
alenm / splitter.swift
Created Feb 5, 2021
Coding problem posted on twitter. The twitter thread has interesting solutions in different languages. This one is in swift
View splitter.swift
// Original Tweet:
// 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 = { String($0) }
alenm / emberjs-lifecycle-hooks.js
Last active Mar 25, 2017
Emberjs Component Lifecycle
View emberjs-lifecycle-hooks.js
// On Intial Render
init() {
didReceiveAttrs() {
alenm / gist:1649365
Created Jan 20, 2012
Toto Archive Group_by
View gist:1649365
# ------------------------------------------------------------
# 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>