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 NS_OPTIONS(uint8_t, CaptureDeviceConfigurationControlPropertyBit) { | |
CaptureDeviceConfigurationControlPropertyBitTorchLevel = 1<< 0, | |
CaptureDeviceConfigurationControlPropertyBitLensPosition = 1<< 1, | |
CaptureDeviceConfigurationControlPropertyBitExposureDuration = 1<< 2, | |
CaptureDeviceConfigurationControlPropertyBitISO = 1<< 3, | |
CaptureDeviceConfigurationControlPropertyBitZoomFactor = 1<< 4, | |
}; | |
typedef CaptureDeviceConfigurationControlPropertyBit CaptureDeviceConfigurationControlPropertyBitMask; | |
CaptureDeviceConfigurationControlPropertyBitMask mask = (CaptureDeviceConfigurationControlPropertyBitTorchLevel | |
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 (^(^(^animation)(void))(ControlState))(void) = ^{ | |
static CGFloat starting_radius, ending_radius, radius_step, radius_val; | |
return ^{ | |
starting_radius = radius; | |
ending_radius = CGRectGetMinX(control_view.layer.bounds); | |
radius_step = 0.0005; //(ending_radius - radius); | |
radius_val = starting_radius; | |
void (^eventHandlerBlock)(void) = ^{ | |
radius_val += radius_step; | |
for (CaptureDeviceConfigurationControlProperty property = CaptureDeviceConfigurationControlPropertyTorchLevel; property < CaptureDeviceConfigurationControlPropertyNone; property++) { |
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
static void (^(^(^touch_handler_init)(UIView *))(UITouch *))(void) = ^ (UIView * view) { | |
CGRect contextRect = view.bounds; | |
float minX = (float)CGRectGetMinX(contextRect); | |
float midX = (float)CGRectGetMidX(contextRect); | |
float mdnX = (float)(((int)midX & (int)minX) + (((int)midX ^ (int)minX) >> 1)); // Average of two floats | |
. | |
. | |
. | |
return ^ (UITouch * touch) { |
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
// Uses XOR to determine whether 'number' is even or odd and... | |
// ...executes the corresponding block | |
// Note: the catch is, in order for the expression to be evaluated, the blocks must return long. Any arbitrary value will do. | |
const long(^ const even_number)(void) = ^ long(void) { | |
printf("even_number\n"); | |
return 2; | |
}; | |
const long(^ const odd_number)(void) = ^ long(void) { |
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
static void (^add_float_arrays)(void) = ^{ | |
float a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
float b[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; | |
float c[] = {[0 ... 9] = NAN}; | |
vDSP_vadd(a, 1, b, 1, c, 1, 10); | |
for (int i = 0; i < 10; i++) printf("%f\n", c[i]); | |
/* | |
Console output: |
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
static long (^(^animate)(long))(void(^__strong)(long *)) = ^ (long duration) { | |
__block typeof(CADisplayLink *) display_link; | |
__block long frames = duration; | |
return ^ long (void (^__strong animator)(long *)) { | |
display_link = [CADisplayLink displayLinkWithTarget:^{ | |
frames >>= 01; | |
return | |
((frames & 01) && | |
^ long { |
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
// Example: | |
// 000100 (the value of bit vector x) returns 16 (use (x << 4) & 1UL to verify) | |
// To find the position of the set bit that returned 16, | |
// use floor(log2(16)) to get 4. | |
// Creates bit vector j and sets the ith bit out of 5… | |
// …returns the value of bit vector j, which is i raised to the power of two (2, 4, 8, 16, 32)… | |
// …returns the position of the set bit in bit vector j, which should coincide with i | |
// | |
for (int i = 1; i < 5; i++) { |
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 | |
// PredicateFunctionsExercise | |
// | |
// Created by James Alan Bush on 3/12/22. | |
// | |
#import "ViewController.h" | |
@import simd; |