Post

Replies

Boosts

Views

Activity

Reply to Swift framework localization
Bundle was the problem. Default bundle is Bundle.main which is App's bundle not the framework bundle. Passing the frameworks bundle fixed the issue. I used Bundle(identifier:) to get the framework's bundle. So the method will look like below. NSLocalizedString("string_key", bundle: Bundle(identifier: "com.framework.bundle") ?? Bundle.main, comment: "Actual String")
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’21
Reply to How to wait until an object is removed from Array
I have declared a class with NSMutableArray initialized and two methods to add and remove. The array count should not exceed 100. If some one calls the method to add an item to that array when the count is 100 then that method should wait until the count goes down to 99 . I want to know how to make the addItem operation to wait until the array count goes down from 100 to 99.
Sep ’21
Reply to How to make one operation wait for another to complete in Objective C
No this is not duplicate. Other thread deals with buffer overflow(array count should not exceed). This thread talks about read/write access. When mutablearray is getting updated(add/remove/insert/exchange), the read operation should be blocked and once write operation is complete, then read operation should continue. Atomic property will help to avoid partial but it won't stop reading the array when its getting updated
Topic: App & System Services SubTopic: General Tags:
Sep ’21
Reply to How to make one operation wait for another to complete in Objective C
Thanks Quinn, I believe you are suggesting the following implementation. Please correct me if I am wrong. @interface ThreadSafeArray() @property (strong, nonatomic) NSMutableArray *data; @end @implementation ThreadSafeArray (instancetype)init { if (self = [super init]) { } return self; } (id)peek { __block id result = nil; dispatch_sync(queue, ^{ result = [self.data firstObject] }); return result; } (NSUInteger)length { __block NSUInteger count = 0; dispatch_sync(queue, ^{ result = [self.data count] }); return count; } (void)enqueue:(id)datum { dispatch_async(queue, ^{ [NSLock lock]; [self.data addObject:datum] ; [NSLock unlock]; }); } @end Can we barrier async instead of lock as shown below. @interface ThreadSafeArray() @property (strong, nonatomic) NSMutableArray *data; @property (strong, nonatomic) dispatch_queue_t queue; @end @implementation ThreadSafeArray (instancetype)init { if (self = [super init]) { queue = dispatch_queue_create("ThreadSafeArray", DISPATCH_QUEUE_CONCURRENT); } return self; } (id)peek { __block id result = nil; dispatch_sync(queue, ^{ result = [self.data firstObject] }); return result; } (NSUInteger)length { __block NSUInteger count = 0; dispatch_sync(queue, ^{ result = [self.data count] }); return count; } (void)enqueue:(id)datum { dispatch_barrier_async(queue, ^{ [self.data addObject:datum] }); } @end
Topic: App & System Services SubTopic: General Tags:
Sep ’21
Reply to How to wait until an object is removed from Array
here is the use case. App will send multiple NSURLSession request to download the catalog and will be adding the catalog downloaded from the server to array. App should not display more that 100 catalog/products. If downloaded product count exceeds zero, app should stop adding product to array and app should block add operation. When app deletes the item(s) then add operation should be unblocked as count will be less than 100.
Sep ’21
Reply to How to make one operation wait for another to complete in Objective C
Thanks Quinn, I believe you are suggesting the following implementation. Please correct me if I am wrong. @property (strong, nonatomic) NSMutableArray *data; @end @implementation ThreadSafeArray -(instancetype)init { if (self = [super init]) { } return self; } -(id)peek { __block id result = nil; dispatch_sync(queue, ^{ result = [self.data firstObject] }); return result; } -(NSUInteger)length { __block NSUInteger count = 0; dispatch_sync(queue, ^{ result = [self.data count] }); return count; } -(void)enqueue:(id)datum { dispatch_async(queue, ^{ [NSLock lock]; [self.data addObject:datum] ; [NSLock unlock]; }); }  @end Can we barrier async instead of lock as shown below. @interface ThreadSafeArray() @property (strong, nonatomic) NSMutableArray *data; @property (strong, nonatomic) dispatch_queue_t queue; @end @implementation ThreadSafeArray - (instancetype)init { if (self = [super init]) { queue = dispatch_queue_create("ThreadSafeArray", DISPATCH_QUEUE_CONCURRENT); } return self; } - (id)peek { __block id result = nil; dispatch_sync(queue, ^{ result = [self.data firstObject]; }); return result; } - (NSUInteger)length { __block NSUInteger count = 0; dispatch_sync(queue, ^{ result = [self.data count] }); return count; } - (void)enqueue:(id)datum { dispatch_barrier_async(queue, ^{ [self.data addObject:datum]; }); }  @end
Topic: App & System Services SubTopic: General Tags:
Oct ’21