Post

Replies

Boosts

Views

Activity

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
Reply to I can not see my app build on App store connect
You can check the upload status in Xcode organizer. Go to Windows -> Organizer and see the upload status.
Replies
Boosts
Views
Activity
Jul ’21
Reply to Weak references
How to determine whether weak self is required or not.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Weak references
Ok, Is there a way to determine whether or not strong reference will create reference cycle.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’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.
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to make one operation wait for another to complete in Objective C
When a condition satisfies(example buffer overflow), then the insert operation should wait until someone calls delete operation so that buffer will not overflow.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to wait until an object is removed from Array
Yes, Array count should not exceed 100. When the count reaches 100, add/insert operation should be blocked until delete operation happens so that buffer overflow will not happen.
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to make one operation wait for another to complete in Objective C
One Shared Resource, Multiple Readers, and a Single Writer
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
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.
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to wait until an object is removed from Array
Quinn- Can you give a code snippet on how to implement? Thanks!
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Oct ’21
Reply to How to make one operation wait for another to complete in Objective C
You said "My general advice, however, is that you not create such a tiny critical section but rather manage your concurrency at a higher level." Could you please add more context and code snippet if possible?
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to Concurrency
We can implement using NSLock or Semaphore. So need which one is better. shouldnt hardcore the strings within while loop, that’s why l put it in a function
Replies
Boosts
Views
Activity
Oct ’21
Reply to Xcode 13.4.1 not responding
I unpaired the connected device as well but still no luck in opening the xcworkspace from Xcode as well as from Finder.
Replies
Boosts
Views
Activity
Jun ’22