Skip to content

Instantly share code, notes, and snippets.

@MrRooni
MrRooni / gist:1402267
Created November 28, 2011 21:55
async'ing a dispatch_release
dispatch_queue_t some_worker_queue = dispatch_queue_create("some_worker_queue", DISPATCH_QUEUE_SERIAL);
dispatch_async(some_worker_queue, ^{
// Perform some work
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_release(some_worker_queue);
});
});
@MrRooni
MrRooni / gist:1528822
Created December 28, 2011 17:37
How to create a negative zero
// Call this method with [NSDecimalNumber zero] to get negative zero, or NaN.
- (NSDecimalNumber *)negativeAmount:(NSDecimalNumber *)anAmount
{
if (anAmount == nil) {
return [NSDecimalNumber zero];
}
NSDecimal decimalAmount = [anAmount decimalValue];
decimalAmount._isNegative = 1;
@MrRooni
MrRooni / gist:2127049
Created March 19, 2012 20:57
How not to increment an NSDate, corrected!
/*
(Updated) Many people reached out on Twitter and directed me towards using NSDateComponents
as the generally accepted method of incrementing a date. Thanks all!
We share a framework between MoneyWell 2.0 (Lion-only) and MoneyWell 1.x (10.5+) that needs
to increment a date variable by 1 second.
Since addTimeInterval: is deprecated in 10.7 and I hate build warnings as much as everyone
else I decided to get fancy with how I go about incrementing a date object. As it turns out
// Update: The plot thickens! In a Mac project you get the behavior outlined below where dragged and dropped
// IBOutlet property creation yields (assign)'ed properties. In an iOS project however, dragged and dropped
// IBOutlets get created thusly:
@property (retain, nonatomic) IBOutlet UIButton *someButton;
// -- Original post begins here:
// Since the inception of properties I've written IBOulet properties like so:
@property (nonatomic, retain) IBOutlet NSButton *someButton;
// Today I dragged and dropped from interface builder to my header file in Xcode 4 to create an outlet and got this:
// How would I define this constraint in the visual format language?
[NSLayoutConstraint constraintWithItem:viewA attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:viewB attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0];
@MrRooni
MrRooni / gist:4988922
Created February 19, 2013 19:16
UITableView and NSFetchedResultsController: Updates Done Right
@interface SomeViewController ()
// Declare some collection properties to hold the various updates we might get from the NSFetchedResultsControllerDelegate
@property (nonatomic, strong) NSMutableIndexSet *deletedSectionIndexes;
@property (nonatomic, strong) NSMutableIndexSet *insertedSectionIndexes;
@property (nonatomic, strong) NSMutableArray *deletedRowIndexPaths;
@property (nonatomic, strong) NSMutableArray *insertedRowIndexPaths;
@property (nonatomic, strong) NSMutableArray *updatedRowIndexPaths;
@end
### Keybase proof
I hereby claim:
* I am MrRooni on github.
* I am mrrooni (https://keybase.io/mrrooni) on keybase.
* I have a public key whose fingerprint is ED23 9DB4 23B8 A856 3526 8735 B6DD 781D 09F9 C73E
To claim this, I am signing this object:

I have a basic List row I am building that has a large number on the leading edge followed by a title and subtitle next to it:

I started with a simple implementation, like so:

HStack {
	Text("26")
		.font(.title)

I'm experiencing a memory usage-based termination in my SwiftUI Apple Watch app. I've traced the problem down to a struct I've created called ImageCycler.

ImageCycler is a view that cycles through an array of images, displaying each one for 1.5 seconds before transitioning to the next. When it reaches the end, it starts back at the beginning. It's powered by the ImageCylerModel. This is how you use it:

struct ImageCycler_Previews: PreviewProvider {
    static var previews: some View {
        ImageCycler(["Image1", "Image2", "Image3", "Image4"])
    }
}