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.
Post
Replies
Boosts
Views
Activity
@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.
I unpaired the connected device as well but still no luck in opening the xcworkspace from Xcode as well as from Finder.
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
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?
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
Quinn- Can you give a code snippet on how to implement? Thanks!
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.
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
One Shared Resource, Multiple Readers, and a Single Writer
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
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.
When a condition satisfies(example buffer overflow), then the insert operation should wait until someone calls delete operation so that buffer will not overflow.
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.
Ok, Is there a way to determine whether or not strong reference will create reference cycle.