Post

Replies

Boosts

Views

Activity

Reply to My iOS app that I created since 2011, crashes on M4 machine (M1 is fine!)
@implementation MOStringDocument - (instancetype)init { self = [super init]; if (self) { // Initialize default values if needed self.data = @""; // Default to an empty string } return self; } - (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError *__autoreleasing *)outError { // Ensure contents is of NSData type if (![contents isKindOfClass:[NSData class]]) { if (outError) { *outError = [NSError errorWithDomain:@"com.cinnamonmobile.StocksLive" code:1001 userInfo:@{NSLocalizedDescriptionKey: @"Invalid contents type. Expected NSData."}]; } NSLog(@"[MOStringDocument] Invalid contents: %@", contents); return NO; } NSData *data = (NSData *)contents; // Check if the data is empty if (data.length == 0) { self.data = @""; // Set an empty string NSLog(@"[MOStringDocument] Loaded empty content."); return YES; } @try { // Attempt to decode the data NSString *decodedString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if (!decodedString) { if (outError) { *outError = [NSError errorWithDomain:@"com.cinnamonmobile.StocksLive" code:1002 userInfo:@{NSLocalizedDescriptionKey: @"Failed to decode NSData as UTF-8 string."}]; } NSLog(@"[MOStringDocument] Failed to decode content as UTF-8 string."); return NO; } // Set the decoded string self.data = decodedString; NSLog(@"[MOStringDocument] Successfully loaded content: %@", self.data); } @catch (NSException *exception) { if (outError) { *outError = [NSError errorWithDomain:@"com.cinnamonmobile.StocksLive" code:1004 userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Exception occurred: %@", exception.reason]}]; } NSLog(@"[MOStringDocument] Exception occurred: %@", exception.reason); } return YES; } - (id)contentsForType:(NSString *)typeName error:(NSError *__autoreleasing *)outError { // Ensure self.data is valid if (!self.data) { self.data = @""; // Default to an empty string } // Convert the string to NSData NSData *data = [self.data dataUsingEncoding:NSUTF8StringEncoding]; if (!data) { if (outError) { *outError = [NSError errorWithDomain:@"com.cinnamonmobile.StocksLive" code:1003 userInfo:@{NSLocalizedDescriptionKey: @"Failed to encode string as NSData."}]; } NSLog(@"[MOStringDocument] Failed to encode string as NSData."); return nil; } NSLog(@"[MOStringDocument] Successfully prepared content for saving."); return data; } @end
Topic: App & System Services SubTopic: General Tags:
Nov ’24
Reply to Gradient rendering issue with alpha set to something other than one
@interface CustomView : UIView @property (nonatomic, strong) NSArray<NSNumber *> *colorsArray; // The color components array // Custom initializer that accepts an NSArray of color components - (instancetype)initWithFrame:(CGRect)frame colors:(NSArray<NSNumber *> *)colorsArray; @end @implementation CustomView // Custom initializer - (instancetype)initWithFrame:(CGRect)frame colors:(NSArray<NSNumber *> *)colorsArray { self = [super initWithFrame:frame]; if (self) { _colorsArray = colorsArray; // Store the colors array } return self; } - (void)drawRect:(CGRect)rect { // Get the current context CGContextRef context = UIGraphicsGetCurrentContext(); // Convert NSArray to a C-style array of CGFloats size_t count = self.colorsArray.count; CGFloat colors[count]; for (size_t i = 0; i < count; i++) { colors[i] = [self.colorsArray[i] floatValue]; } // Create a color space CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // Create the gradient with the passed colors CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, NULL, count / 4); // Define the start and end points of the gradient CGPoint startPoint = CGPointMake(rect.origin.x, rect.origin.y); CGPoint endPoint = CGPointMake(rect.origin.x, rect.origin.y + rect.size.height); // Draw the rectangle with the gradient CGContextSaveGState(context); CGContextAddRect(context, rect); CGContextClip(context); CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0); CGContextRestoreGState(context); // Release resources CGGradientRelease(gradient); CGColorSpaceRelease(colorSpace); } @end @interface ViewController : UIViewController @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Get the screen bounds CGRect screenBounds = [UIScreen mainScreen].bounds; // Define the size of each custom view CGFloat customViewWidth = screenBounds.size.width * 0.75; CGFloat customViewHeight = screenBounds.size.height * 0.75; // Define a dynamic set of colors for the first custom view (red to blue) NSArray<NSNumber *> *colorsArray1 = @[ @1.0, @0.0, @0.0, @1.0, // Red @0.0, @0.0, @1.0, @1.0 // Blue ]; // TODO: This is the bug, there is no transparency NSNumber *alpha = @0.0;// this is the ***** bug **** // Define a dynamic set of colors for the second custom view (green to yellow) NSArray<NSNumber *> *colorsArray2 = @[ @0.0, @1.0, @0.0, alpha, // Green @1.0, @1.0, @0.0, @1.0 // Yellow ]; // Calculate the position for the first view (centered horizontally and vertically, with slight offset) CGRect frame1 = CGRectMake((screenBounds.size.width - customViewWidth) / 2 - customViewWidth * 0.25, (screenBounds.size.height - customViewHeight) / 2 - customViewHeight * 0.25, customViewWidth, customViewHeight); CustomView *customView1 = [[CustomView alloc] initWithFrame:frame1 colors:colorsArray1]; // Calculate the position for the second view (slightly shifted from the first view to partially overlap) CGRect frame2 = CGRectMake((screenBounds.size.width - customViewWidth) / 2 + customViewWidth * 0.25, (screenBounds.size.height - customViewHeight) / 2 + customViewHeight * 0.25, customViewWidth, customViewHeight); CustomView *customView2 = [[CustomView alloc] initWithFrame:frame2 colors:colorsArray2]; // Set autoresizing so they adjust with the screen size customView1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; customView2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // Add the custom views to the view controller's view [self.view addSubview:customView1]; [self.view addSubview:customView2]; } @end
Oct ’24
Reply to Gradient rendering issue with alpha set to something other than one
Gradient with colors that have alpha channel works fine.
Replies
Boosts
Views
Activity
Mar ’25
Reply to My iOS app that I created since 2011, crashes on M4 machine (M1 is fine!)
@implementation MOStringDocument - (instancetype)init { self = [super init]; if (self) { // Initialize default values if needed self.data = @""; // Default to an empty string } return self; } - (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError *__autoreleasing *)outError { // Ensure contents is of NSData type if (![contents isKindOfClass:[NSData class]]) { if (outError) { *outError = [NSError errorWithDomain:@"com.cinnamonmobile.StocksLive" code:1001 userInfo:@{NSLocalizedDescriptionKey: @"Invalid contents type. Expected NSData."}]; } NSLog(@"[MOStringDocument] Invalid contents: %@", contents); return NO; } NSData *data = (NSData *)contents; // Check if the data is empty if (data.length == 0) { self.data = @""; // Set an empty string NSLog(@"[MOStringDocument] Loaded empty content."); return YES; } @try { // Attempt to decode the data NSString *decodedString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if (!decodedString) { if (outError) { *outError = [NSError errorWithDomain:@"com.cinnamonmobile.StocksLive" code:1002 userInfo:@{NSLocalizedDescriptionKey: @"Failed to decode NSData as UTF-8 string."}]; } NSLog(@"[MOStringDocument] Failed to decode content as UTF-8 string."); return NO; } // Set the decoded string self.data = decodedString; NSLog(@"[MOStringDocument] Successfully loaded content: %@", self.data); } @catch (NSException *exception) { if (outError) { *outError = [NSError errorWithDomain:@"com.cinnamonmobile.StocksLive" code:1004 userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Exception occurred: %@", exception.reason]}]; } NSLog(@"[MOStringDocument] Exception occurred: %@", exception.reason); } return YES; } - (id)contentsForType:(NSString *)typeName error:(NSError *__autoreleasing *)outError { // Ensure self.data is valid if (!self.data) { self.data = @""; // Default to an empty string } // Convert the string to NSData NSData *data = [self.data dataUsingEncoding:NSUTF8StringEncoding]; if (!data) { if (outError) { *outError = [NSError errorWithDomain:@"com.cinnamonmobile.StocksLive" code:1003 userInfo:@{NSLocalizedDescriptionKey: @"Failed to encode string as NSData."}]; } NSLog(@"[MOStringDocument] Failed to encode string as NSData."); return nil; } NSLog(@"[MOStringDocument] Successfully prepared content for saving."); return data; } @end
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’24
Reply to Gradient rendering issue with alpha set to something other than one
@interface CustomView : UIView @property (nonatomic, strong) NSArray<NSNumber *> *colorsArray; // The color components array // Custom initializer that accepts an NSArray of color components - (instancetype)initWithFrame:(CGRect)frame colors:(NSArray<NSNumber *> *)colorsArray; @end @implementation CustomView // Custom initializer - (instancetype)initWithFrame:(CGRect)frame colors:(NSArray<NSNumber *> *)colorsArray { self = [super initWithFrame:frame]; if (self) { _colorsArray = colorsArray; // Store the colors array } return self; } - (void)drawRect:(CGRect)rect { // Get the current context CGContextRef context = UIGraphicsGetCurrentContext(); // Convert NSArray to a C-style array of CGFloats size_t count = self.colorsArray.count; CGFloat colors[count]; for (size_t i = 0; i < count; i++) { colors[i] = [self.colorsArray[i] floatValue]; } // Create a color space CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // Create the gradient with the passed colors CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, NULL, count / 4); // Define the start and end points of the gradient CGPoint startPoint = CGPointMake(rect.origin.x, rect.origin.y); CGPoint endPoint = CGPointMake(rect.origin.x, rect.origin.y + rect.size.height); // Draw the rectangle with the gradient CGContextSaveGState(context); CGContextAddRect(context, rect); CGContextClip(context); CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0); CGContextRestoreGState(context); // Release resources CGGradientRelease(gradient); CGColorSpaceRelease(colorSpace); } @end @interface ViewController : UIViewController @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Get the screen bounds CGRect screenBounds = [UIScreen mainScreen].bounds; // Define the size of each custom view CGFloat customViewWidth = screenBounds.size.width * 0.75; CGFloat customViewHeight = screenBounds.size.height * 0.75; // Define a dynamic set of colors for the first custom view (red to blue) NSArray<NSNumber *> *colorsArray1 = @[ @1.0, @0.0, @0.0, @1.0, // Red @0.0, @0.0, @1.0, @1.0 // Blue ]; // TODO: This is the bug, there is no transparency NSNumber *alpha = @0.0;// this is the ***** bug **** // Define a dynamic set of colors for the second custom view (green to yellow) NSArray<NSNumber *> *colorsArray2 = @[ @0.0, @1.0, @0.0, alpha, // Green @1.0, @1.0, @0.0, @1.0 // Yellow ]; // Calculate the position for the first view (centered horizontally and vertically, with slight offset) CGRect frame1 = CGRectMake((screenBounds.size.width - customViewWidth) / 2 - customViewWidth * 0.25, (screenBounds.size.height - customViewHeight) / 2 - customViewHeight * 0.25, customViewWidth, customViewHeight); CustomView *customView1 = [[CustomView alloc] initWithFrame:frame1 colors:colorsArray1]; // Calculate the position for the second view (slightly shifted from the first view to partially overlap) CGRect frame2 = CGRectMake((screenBounds.size.width - customViewWidth) / 2 + customViewWidth * 0.25, (screenBounds.size.height - customViewHeight) / 2 + customViewHeight * 0.25, customViewWidth, customViewHeight); CustomView *customView2 = [[CustomView alloc] initWithFrame:frame2 colors:colorsArray2]; // Set autoresizing so they adjust with the screen size customView1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; customView2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; // Add the custom views to the view controller's view [self.view addSubview:customView1]; [self.view addSubview:customView2]; } @end
Replies
Boosts
Views
Activity
Oct ’24
Reply to Curious sheet behaviour
Still happening inXcode 13.3. Maybe in XCode 100.5 will be fixed!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’22
Reply to iOS 15 affecting in-app purchases
Stocks live app suffers from the same issue. I don’t understand why Apple doesn’t do anything about this. This is really messed up. Also, iOS 15.1 didn’t fix the issue.
Topic: App & System Services SubTopic: StoreKit Tags:
Replies
Boosts
Views
Activity
Nov ’21