This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is similar to using callback blocks with three key differences: | |
// 1. Blocks stored in an array retain their arguments outside of the context in whicn they were created | |
// 2. Blocks can be called in combination or in a variance of succession | |
// 3. The number of blocks to be executed is known up-front | |
// The same effect could be achieved via regular callback blocks; however, the argument values would not be persistent | |
typedef int(^BlockObject)(void); | |
- (void)test { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "GlobalQueue.h" | |
dispatch_queue_t queue; | |
dispatch_queue_t queue_ref(void) { | |
if (!queue) { | |
queue = dispatch_queue_create_with_target("GlobalDispatchQueue", DISPATCH_QUEUE_SERIAL, dispatch_get_main_queue()); | |
} | |
return queue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ViewController.h" | |
@interface ViewController () | |
@property (nonatomic) int a; | |
@property (nonatomic) int b; | |
@property (nonatomic) int c; | |
@property (nonatomic) int d; | |
@property (nonatomic) int e; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// TargetActionCustomPayloadsDemo | |
// | |
// Created by James Alan Bush on 9/18/21. | |
// | |
#import "ViewController.h" | |
@interface ViewController () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect { | |
__autoreleasing NSArray<UICollectionViewLayoutAttributes *> * collectionViewLayoutAttributes; | |
[self performSelector:@selector(changeLayoutAttributes:) withObject:[collectionViewLayoutAttributes = [[NSArray alloc] initWithArray:[super layoutAttributesForElementsInRect:rect] copyItems:TRUE] self]]; | |
return (NSArray<UICollectionViewLayoutAttributes *> *)collectionViewLayoutAttributes; | |
} | |
- (void)changeLayoutAttributes:(NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributes { | |
for (UICollectionViewLayoutAttributes * attribute in layoutAttributes) { | |
// change attribute code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect { | |
__autoreleasing NSArray<UICollectionViewLayoutAttributes *> * collectionViewLayoutAttributes; | |
[[collectionViewLayoutAttributes = [[NSArray alloc] initWithArray:[super layoutAttributesForElementsInRect:rect] copyItems:TRUE] self] enumerateObjectsUsingBlock:^ (UICollectionViewLayoutAttributes * selected_attributes) { | |
return ^(UICollectionViewLayoutAttributes * _Nonnull attributes, NSUInteger idx, BOOL * _Nonnull stop) { | |
// Configure each attributes object in the collection individually | |
// based on the configuration of a single attributes object in that same collection | |
}; | |
}(^ UICollectionViewLayoutAttributes * (NSArray<NSIndexPath *> * visible_index_paths) { | |
UICollectionViewLayoutAttributes * selectedAttributes = nil; | |
for (NSIndexPath * indexPath in visible_index_paths) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct __attribute__((objc_boxable)) ArcDegreesMeasurements ArcDegreesMeasurements; | |
typedef NSUInteger (^(^ArcDegreesMeasurementsEnd)(void))(void); | |
struct __attribute__((objc_boxable)) ArcDegreesMeasurements | |
{ | |
NSUInteger start; | |
NSUInteger length; | |
__unsafe_unretained ArcDegreesMeasurementsEnd end; | |
NSUInteger sectors; | |
} arcDegreesMeasurements = { | |
.start = 0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | |
^ (UITouch * touch) { | |
CGPoint center = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect)); | |
CGPoint tp = [touch preciseLocationInView:touch.view]; | |
CGFloat radius = sqrt(pow(tp.x - center.x, 2.0) + pow(tp.y - center.y, 2.0)); | |
UIBezierPath * bezier_quad_curve = [UIBezierPath bezierPathWithArcCenter:center | |
radius:radius | |
startAngle:degreesToRadians(270.0) | |
endAngle:degreesToRadians(180.0) | |
clockwise:FALSE]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void (^eventHandlerBlock)(void) = ^{ | |
printf("\nHandling event for button %lu\n", some_local_variable); | |
}; | |
objc_setAssociatedObject(button, @selector(invoke), eventHandlerBlock, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
[button addTarget:eventHandlerBlock action:@selector(invoke) forControlEvents:UIControlEventAllEvents]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Continuously monitor the run state of an app | |
# identified by the specified name and | |
# launches the app if not running | |
while (true); do | |
ps_out=`ps -ef | grep $1 | grep -v 'grep' | grep -v $0` | |
result=$(echo $ps_out | grep "$1") | |
if [[ "$result" == "" ]]; then | |
open -a /Applications/AVS\ Server.app/ | |
osascript -e "set volume input volume 100" |