我当然记得在以前的 Xcode 版本中可以跳转到系统类的定义(例如NSWindow
)。但在 16.2 中却不行。这是需要启用的设置,还是我的设置出了问题,或者是故意更改功能?
编辑:似乎我的 Xcode 设置出了问题。它按预期跳转到我的类的定义,但没有跳转到框架类的定义。就好像有一个索引可以启用跳转逻辑,并且需要为 MacOS SDK 本身重建它……
我当然记得在以前的 Xcode 版本中可以跳转到系统类的定义(例如NSWindow
)。但在 16.2 中却不行。这是需要启用的设置,还是我的设置出了问题,或者是故意更改功能?
编辑:似乎我的 Xcode 设置出了问题。它按预期跳转到我的类的定义,但没有跳转到框架类的定义。就好像有一个索引可以启用跳转逻辑,并且需要为 MacOS SDK 本身重建它……
我有一些用 ARC 编译的 Objective C 代码:
void func(void) {
NSString *string;
// Do some stuff. Maybe return early.
string = @"initialized";
// Other stuff.
}
ARC 如何处理未初始化的对象指针?我假设它像 C 指针一样,string
最初包含堆栈垃圾。如果是这样,那么如果我要在初始化变量之前返回,ARC 如何知道如何处理它?
我是否需要将其初始化为,nil
以避免内存泄漏?
如果引用的是调度对象或块而不是,这有关系吗NSObject
?
所以我这里有一个涉及块的片段:
NSArray<Class> *acceptableClasses = @[[DesktopEntity class]];
__block NSInteger insertIdx = row;
[info enumerateDraggingItemsWithOptions:0 forView:_tableView classes:acceptableClasses searchOptions:nil usingBlock:^(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop)
{
DesktopEntity *entity = draggingItem.item;
[_tableContents insertObject:entity atIndex: insertIdx];
[_tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:insertIdx] withAnimation:NSTableViewAnimationEffectGap];
draggingItem.draggingFrame = [_tableView frameOfCellAtColumn:0 row: insertIdx];
++insertIdx;
}];
它可以很好地编译,但我收到一个警告:
Block 隐式保留“self”;明确提及“self”以表明这是预期行为
我有点不明白它的意思。我通过在变量前输入 self 关键字来让警告消失:
[self.tableContents insertObject:entity atIndex: insertIdx];
[self.tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:insertIdx] withAnimation:NSTableViewAnimationEffectGap];
draggingItem.draggingFrame = [self.tableView frameOfCellAtColumn:0 row: insertIdx];
++insertIdx;
但我也看到有人使用这样的结构
__weak typeof(self) weakSelf = self;
然后改用这个“weakSelf”,这里有什么区别?我的第一种方法是否错误?
我刚刚从 XCode 13 更新到 14.3,速度确实很慢。我看到五颜六色的末日之轮正在运行测试,这导致 XCode 14.3 大约 2-5 分钟没有响应。在 XCode 中执行大量任务时,甚至访问菜单栏时,都会发生这种情况。
我做了很多研究。但没有找到正确的解决方案。
任何建议都很好。
我正在使用 Objective-C 开发 iOS 框架。
我dispatch_queue_t
通过使用创建了一个dispatch_queue_create
. 并调用CFRunLoopRun()
运行队列中的runloop。
但是,看起来dispatch_queue_t共享了RunLoop。有些类添加了一个无效的计时器,当我调用它时CFRunLoopRun()
,它在我这边崩溃了。
- (void)viewDidLoad {
[super viewDidLoad];
self.queue1 = dispatch_queue_create("com.queue1", DISPATCH_QUEUE_CONCURRENT);
self.queue2 = dispatch_queue_create("org.queue2", DISPATCH_QUEUE_CONCURRENT);
}
- (IBAction)btnButtonAction:(id)sender {
dispatch_async(self.queue1, ^{
NSString *runloop = [NSString stringWithFormat:@"%@", CFRunLoopGetCurrent()];
runloop = [runloop substringWithRange:NSMakeRange(0, 22)];
NSLog(@"Queue1 %p run: %@", self.queue1, runloop);
//NSTimer *timer = [[NSTimer alloc] initWithFireDate:[NSDate date] interval:1 target:self selector:@selector(wrongSeletor:) userInfo:nil repeats:NO];
//[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
});
dispatch_async(self.queue2, ^{
NSString *runloop = [NSString stringWithFormat:@"%@", CFRunLoopGetCurrent()];
runloop = [runloop substringWithRange:NSMakeRange(0, 22)];
NSLog(@"Queue2 %p run: %@", self.queue2, runloop);
CFRunLoopRun();
});
}
有时他们采用相同的 RunLoop:
https://isstatic.askoverflow.dev/wGcv3.png
=====
您可以通过取消注释代码来查看崩溃情况NSTimer
。NSTimer已添加,但调用queue1
时仍在运行。CFRunLoopRun()
queue2
我读过一些描述,例如:需要一些有关调度队列、线程和 NSRunLoop 的说明
他们告诉我们:system creates a run loop for the thread
。但是,在我的检查中,他们正在共享 RunLoop。
这对我来说很伤心,因为我在调用生产时面临着崩溃的情况CFRunLoopRun()
。
如果我为已定义的属性指定属性,它对默认属性配置有什么影响吗?
例如,以下声明是相等的,因为atomic, readwrite and strong
默认设置
@property(atomic,readwrite,strong)NSString *name;
@property NSString *name;
如果我用 attribute 声明属性assign
,它会保留其他属性吗?
这两个陈述等价吗?
@property (assign) NSString* name;
@property (assign,atomic,readwrite,strong) NSString * name;
如果我更改一个默认属性,会发生什么情况,是否会将另一个属性保留为默认设置?这两个陈述等价吗?
@property (nonatomic,weak) NSString * name;
@property (nonatomic,weak,readwrite) NSString * name;
我问这个问题是因为当我仅使用属性设置属性时assign
,该strong
属性看起来不再应用,因为当我使用另一个变量设置它时,它不会保留引用。