Skip to content

Instantly share code, notes, and snippets.

View astericky's full-sized avatar

Chris Sanders astericky

View GitHub Profile
@astericky
astericky / examples.md
Created May 29, 2019 00:00 — forked from ErisDS/examples.md
Ghost Filter Query examples

Filter Queries - Example Use Cases

Here are a few example use cases, these use cases combine filter with other parameters to make useful API queries. The syntax for any of this may change between now, implementation, and release - they're meant as illustrative examples :)

Fetch 3 posts with tags which match 'photo' or 'video' and aren't the post with id 5.

api.posts.browse({filter: "tags:[photo, video] + id:-5", limit="3"});

GET /api/posts?filter=tags%3A%5Bphoto%2Cvideo%5D%2Bid%3A-5&limit=3

@astericky
astericky / SwiftUICollectionChanges.md
Created June 12, 2019 16:23 — forked from epatey/SwiftUICollectionChanges.md
Refreshing SwiftUI on changes within objects in a collection.

Refreshing SwiftUI on changes within objects in a collection.

How to approach updating UI for changes within objects held within a collection? After experimenting a bit, I think there are basically two approaches.

  1. The conformance to BindableObject by the object that contains the collection needs to be deep and not shallow. It needs to fire didChange if the collection, or anything recursively within the collection, changes. In my example from yesterday, this means that MainViewModel would need to figure out how to fire didChange if anything within any of its existing rows changes - not just changes to the collection itself. or
  2. The parent/container can have shallow conformance to BindableObject if the row model themselves conform to BindableObject and the row view declares the dependency with @ObjectBinding.

You must do one or the other if you want a row to refresh when isTyping changes value. I suspect that in the general case, #2 will be simpler.

@astericky
astericky / SwiftUI+HexColors.swift
Last active June 22, 2019 20:36 — forked from aChase55/SwiftUI+HexColors.swift
SwiftUI Hex Colors
//Trying out a prefix operator
//I thought vertical elipses made sense, representative of rbg
prefix operator ⋮
prefix func ⋮(hex:UInt32) -> Color {
return Color(hex)
}
extension Color {
init(_ hex: UInt32, opacity:Double = 1.0) {
let red = Double((hex & 0xff0000) >> 16) / 255.0
@astericky
astericky / Date.swift
Created October 7, 2020 19:44 — forked from alexpaul/Date.swift
Using Date in Swift, using ISO8601DateFormatter() and DateFormatter()
// Date extension
extension Date {
static func getStringFromDate(date: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE, MMM d, yyyy"
let dateString = dateFormatter.string(from: date)
return dateString
}
static func getDateFromString(dateString: String) -> Date? {
let formatter = ISO8601DateFormatter()