Skip to content

Instantly share code, notes, and snippets.

View mattmassicotte's full-sized avatar

Matt Massicotte mattmassicotte

View GitHub Profile
@mattmassicotte
mattmassicotte / SendableCapture.swift
Created September 22, 2023 10:30
Capturing a non-Sendable in a @sendable closure that produces no warning
struct NonSendable {
}
@available(*, unavailable)
extension NonSendable: Sendable {
}
actor MyActor {
let nonSendable: NonSendable
@mattmassicotte
mattmassicotte / AsyncMap.swift
Created June 18, 2022 11:00
Swift asyncMap function
extension Sequence {
func asyncMap<T>(_ transform: @escaping (Element) async -> T) async -> [T] {
return await withTaskGroup(of: T.self) { group in
var transformedElements = [T]()
for element in self {
group.addTask {
return await transform(element)
}
}
@mattmassicotte
mattmassicotte / shared_publisher.swift
Last active May 21, 2022 15:12
This code demonstrates that using a shared publisher will not always be able to deliver results to concurrent subscribers
import Foundation
import Combine
enum State: Int {
case starting
case firstValueReceived
case secondSubscriptionCreated
case finishedWithFirstValue
case secondValueReceived
case finished
func testCurrentYearAppearsInInfoPlistCopyright() throws {
let bundle = Bundle(for: AppDelegate.self)
let plist = try XCTUnwrap(bundle.localizedInfoDictionary)
let string = try XCTUnwrap(plist["NSHumanReadableCopyright"] as? String)
let formatter = DateFormatter()
formatter.dateFormat = "yyyy"
return (
<MultiChildComponent>
<ChildNode key="child1">
<span>Yo</span>
</ChildNode>
<ChildNode key="child2">
<span>Dawg</span>
</ChildNode>
</MultiChildComponent>
);
@mattmassicotte
mattmassicotte / arm-test.m
Created September 19, 2012 15:26
Test input for arm assembly differences
// clang -arch armv7 -framework Foundation -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk -S arm-test.m -o armv7-test.s
#import <Foundation/Foundation.h>
int main(const int argc, const char* const* argv) {
@autoreleasepool {
NSString* string;
string = @"hello";
@mattmassicotte
mattmassicotte / gist:3150651
Created July 20, 2012 13:11
Dot-syntax assignment versus traditional assignment
// clang -framework Foundation -c properties.m
#import <Foundation/Foundation.h>
@interface PropertyBug : NSObject {
NSString* _value;
}
@property (copy) NSString* value;