Skip to content

Instantly share code, notes, and snippets.

View mfaani's full-sized avatar

Mohammad Faani mfaani

View GitHub Profile
@mfaani
mfaani / some-vs-some.md
Last active September 30, 2024 18:09
`some Equatable` vs another `some Equatable`
var a: some Equatable = 10
var c: some Equatable = 10
a = c // ERROR: Cannot assign value of type 'some Equatable' (type of 'c') to type 'some Equatable' (type of 'a')

You can't pass a different some Equatable to a. The compiler can't guarantee if a and c have identical underlying concrete types. Even though on the screen you can see c is an Int, to the compiler it's just some Equatable. It's NOT some Equatable_But_really_an_Int.

Because it's some Equatable then the compiler would be like, then 'What if c was "ten"? Let's just be safe an not allow it'

extension Character: Strideable {
public func distance(to other: Character) -> Int {
let selfValue = self.unicodeScalars.first?.value ?? 0
let otherValue = other.unicodeScalars.first?.value ?? 0
return Int(otherValue - selfValue)
}
public func advanced(by n: Int) -> Character {
guard let scalar = self.unicodeScalars.first else {
fatalError("Cannot advance an empty character")
@mfaani
mfaani / EmojiRanger-watchos-simulator-error.md
Last active April 6, 2025 21:59
EmojiRanger-watchos-simulator-error.md

This happened after it successfully built, but didn't launch.

Simulator device failed to install the application.
Domain: IXErrorDomain
Code: 2
Failure Reason: Invalid placeholder attributes.
User Info: {
    DVTErrorCreationDateKey = "2025-04-06 19:35:47 +0000";
    FunctionName = "+[IXPlaceholder _placeholderForBundle:client:withParent:installType:metadata:placeholderType:mayBeDeltaPackage:isFromSerializedPlaceholder:error:]";