Post

Replies

Boosts

Views

Activity

Reply to Swift files in Bundle
Thanks @polyphonic. A, B, C and D in framework Y is dependent on framework X and vice versa. That’s why l am looking for some kind of container instead of a framework to separate those files from framework X. I tried moving those files in .bundle but it didn’t work either.
Sep ’22
Reply to Swift files in Bundle
@Polyphonic You said "you generally need to create a module", I believe you are asking to create a framework or SPM or static library. If not, then how to create the module . I tried creating framework/target/SPM but facing compilation errors due to dependency. I have a framework with 50+ classes and I want to move 4 files outside of this project. Let's say, I have to move Class A,B, C and D out side of the framework. These 4 classes are accesing other few classes from the main framework and more main framework is accessing Class A,B,C and D. So getting compilation error. I want some sort of container(other than folder) to keep those 4 files separate locally and access them in the main framework.
Sep ’22
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
Oct ’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. @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
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
Sep ’21