I'm taking a step further today.
git commit -m "Drop the bird link."
Posting on your own website doesn't just mean to own your content, it also pushes yourself to think deliberately before any post. They are no longer the raw first thoughts, but words that went through your digestive system.
∞ People Spend Too Much Time On Decisions with Equally Satisfying Outcomes
Rob Henderson writes,
The researchers conclude, “people apparently misallocate their time, spending too much on those choice problems in which the relative reward is low.”
In software engineering, I'm sure a lot of us have spent way too much time on deciding an implementation detail. Rather, we should just pick one and move on. If it's really the wrong decision, it will come back at you later. There are surprisingly more decisions you can reverse at a later time.
∞ Selective Empathy Prevents Us From Making Connections
If we Americans are appalled at the Russian killing of children, why don’t we teach to our own children the words of Gen. Jacob H. Smith, who ordered his soldiers to “kill everyone over 10” in the Philippine-American War? Or the 1864 Sand Creek massacre, when US Army troops massacred about 150 Cheyenne and Arapaho people, two-thirds of whom were women and children?
Great piece by Viet Thanh Nguyen.
Mango 5Star v2022.1
Image shared via Mango 5Star v2021.1
Mango 5Star v2022.1 is now available. What's new:
- DA 5Star is now Mango 5Star, a product under the Mango Umbrella.
- Support sharing reviews as an image.
Happy cheering yourself up with the 5-star reviews ^_^
iOS: How to Enable the Save Image Option in Share Sheet
When you want to present a share sheet to share an image, it isn't hard to figure out how to use UIActivityViewController
. All you need is to prepare an UIImage
or a URL
pointing to an image:
let controller = UIActivityViewController(
activityItems: [image], applicationActivities: nil)
present(controller, animated: true)
However, you won't see the "Save Image" option in the share sheet by default. The reason you don't see this option is unintuitive, but it actually requires the host app to have the permission writing to the photo library.
Since this action directly saves the image in user's photo library, you want to enable this convenient option. To do this, open your project's Info.plist
file, add a "Privacy - Photo Library Additions Usage Description", and give it a value like "Support saving images to the photo library".
SwiftUI: How to Add an Inverted Mask
SwiftUI's mask(alignment:_:)
method allows you to mask the view using the alpha channel of a given view. However, sometime you want to add an inverted mask. There are a few ways to achieve this depending on how your mask view is constructed.
Example of inverted mask effect.
Use eoFill
If your mask is a shape, you can create another shape by adding a Rectangle
path and applying a FillStyle(eoFill: true)
:
struct CircleInRectangle: Shape {
let padding: CGFloat
func path(in rect: CGRect) -> Path {
var shape = Rectangle().path(in: rect)
let paddedRect = rect.insetBy(dx: padding, dy: padding)
shape.addPath(Circle().path(in: paddedRect))
return shape
}
}
struct ContentView: View {
var body: some View {
Image(uiImage: #imageLiteral(resourceName: "img.jpeg"))
.resizable()
.scaledToFill()
.clipped()
.frame(width: 400, height: 225)
.background(.white)
.mask(
CircleInRectangle(padding: 24)
.fill(style: .init(eoFill: true))
)
)
}
}
Use .luminanceToAlpha()
SwiftUI's .luminanceToAlpha()
modifier creates a mask by making dark colors transparent and bright colors opaque.
struct ContentView: View {
var body: some View {
Image(uiImage: #imageLiteral(resourceName: "pattern.jpeg"))
.resizable()
.scaledToFill()
.clipped()
.frame(width: 400, height: 225)
.background(.white)
.mask(
Circle()
.padding()
.foregroundColor(.black)
.background(.white)
.compositingGroup()
.luminanceToAlpha()
)
}
}
Use .blendMode(.destinationOut)
SwiftUI's .blendMode(.destinationOut)
modifier allows you to erase any of the background that is covered by opaque source pixels.
struct ContentView: View {
var body: some View {
Image(uiImage: #imageLiteral(resourceName: "pattern.jpeg"))
.resizable()
.scaledToFill()
.clipped()
.frame(width: 400, height: 225)
.background(.white)
.mask(
Color.black
.overlay(
Circle()
.padding()
.blendMode(.destinationOut)
)
.compositingGroup()
)
}
}
Swift: The Direction of Date.distance(to:)
The official document of Date.distance(to:)
says it:
Returns the distance from this date to another date, specified as a time interval.
But it has never been clear to me positive distance means whether the left side date is earlier or later.
So this tip is dedicated to myself: Date.distance(to:)
is the opposite of minus. The distance positive when the left side date is earlier.
$ swift
1> let now = Date()
now: Date = {}
2> let oneHourLater = now.advanced(by: 3600)
oneHourLater: Date = {}
3> let distance = now.distance(to: oneHourLater)
distance: TimeInterval = 3600
Finally scheduled my long overdue car service appointment, and just realized that I can carry my bike in my car, drop off my car, and bike back home.
Why hasn't this idea occurred to me before? What has US done to me?
I need to change.
DA 5Star v2021.3
DA 5Star v2021.3 for both iOS and macOS is now available:
- Added a button in Diagnostics to refresh app icons / podcast artwork images.
- It now clears the local artwork images when an app is deleted.
Happy cheering yourself up with the 5-star reviews ^_^