小编Pet*_*isu的帖子

NSFontManager addFontTrait如何更改UI元素上的实际字体

我想实现与[[NSFontManager sharedFontManager] addFontTrait:(nullable id)sender]仅使用我的代码相同的事情

医生说

This action method causes the receiver to send its action 
message up the responder chain.
By default, the action message is changeFont:.
When a responder replies by providing a font to convert in
a convertFont: message, the receiver converts the font by 
adding the trait specified by sender. This trait is determined 
by sending a tag message to sender and interpreting it as a font 
trait mask for a convertFont:toHaveTrait: message.
Run Code Online (Sandbox Code Playgroud)

所以我试过

NSFontManager …
Run Code Online (Sandbox Code Playgroud)

cocoa nstextfield nstextview nsfontmanager

7
推荐指数
1
解决办法
270
查看次数

构造函数调用已创建的对象

如果我在已经构造的对象或结构上调用构造函数,它会分配新空间,还是只使用现有空间?那么第一个对象分配是否更加资源密集?像这样:

struct F {
    int a,b,c,d;
    F(int _a, int _b) {a = _a; b = _b}; 
    void a(int _a, int _b) {a = _a; b = _b};
};  

//first constructor call
F f = F(5, 6);

//second constructor call on an already constructed object
f = F(7, 8);

//third constructor call on an already constructed object
f(7, 8);

//is the constructor call more res. intesive, than the call to a function which does the same? 
f.a(9, 0)
Run Code Online (Sandbox Code Playgroud)

构造函数是否调用了更多的资源intesive,而不是调用一个执行相同(void a(...) …

c++ memory constructor allocation

6
推荐指数
1
解决办法
8649
查看次数

NSDictionary的描述 - 为什么一些带引号的关键名称?

我在字典上使用了一个简单的NSLog

NSLog(@"dict %@", dictionary); 
Run Code Online (Sandbox Code Playgroud)

我得到的结果是

...
"first_name" = Peter;
gender = male;
id = 1171548848;
"last_name" = Lapisu;
...
Run Code Online (Sandbox Code Playgroud)

为什么在"引号"中有一些关键名称,有些则不是?

cocoa objective-c nsdictionary

6
推荐指数
1
解决办法
895
查看次数

NSCalendar,为什么设置第一个周末不影响计算结果?

我需要计算给定日期的工作日,但是,根据日历,一周可以在星期一加星,在星期日看星期日

所以我想设置它,从周一开始,使用

[[NSCalendar currentCalendar] setFirstWeekday:2];
Run Code Online (Sandbox Code Playgroud)

但是,计算结果是一样的

{
    [[NSCalendar currentCalendar] setFirstWeekday:1];
    NSDateComponents *weekdayComponents = [[NSCalendar currentCalendar] components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:date];
    NSInteger weekday = [weekdayComponents weekday] - 1;
    NSLog(@"%d", weekday);
}
{
    [[NSCalendar currentCalendar] setFirstWeekday:2];
    NSDateComponents *weekdayComponents = [[NSCalendar currentCalendar] components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:date];
    NSInteger weekday = [weekdayComponents weekday] - 1;
    NSLog(@"%d", weekday);
}
Run Code Online (Sandbox Code Playgroud)

返回相同的数字,但为什么?

cocoa nsdate nscalendar ios

6
推荐指数
2
解决办法
6799
查看次数

NSDictionary allKeys返回NSArray,而不是NSSet

我想知道NSDictionary方法allKeys背后的决定是什么,返回一个NSArray,而不是NSSet,这将更有意义,因为不能保证返回数组的顺序,而且,一个键是唯一的

cocoa objective-c nsdictionary

6
推荐指数
1
解决办法
925
查看次数

Cocoa dispatch_once每个实例

如何使用displatch_once,因此每个实例生命周期执行一次给定的代码

等价的是在对象中有一个属性,并像这样使用它

- (void)viewWillAppear:(..).. {

   ...

   if (self.isDisplatched == NO) {
      ...
      self.isDisplatched = YES;
   }

}
Run Code Online (Sandbox Code Playgroud)

但我不想使用额外的属性,而是dispatch_once_t或simmilar

cocoa objective-c ios

6
推荐指数
1
解决办法
1694
查看次数

iOS 8.3及更高版本,未插入Facebook共享文本

更新到iOS 8.3后,文本不会插入共享对话框

我使用标准

UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:applicationActivities];
NSArray *excludeActivities = @[UIActivityTypeAssignToContact];
vc.excludedActivityTypes = excludeActivities;

if (IsUserInterfaceIdiomPad) {
    vc.popoverPresentationController.sourceView = self.navigationController.view;
}
[self.navigationController presentViewController:vc animated:YES completion:^{

}];
Run Code Online (Sandbox Code Playgroud)

其中的项目是NSString和NSURL

cocoa-touch facebook objective-c ios

6
推荐指数
1
解决办法
6559
查看次数

为什么不能为NSTextView提供弱参考?

我注意到比在OSX中,NSTextView不能用于弱反射(如果你尝试将它连接起来很弱,你会得到)

Cannot form weak reference to instance (0x600000122da0) of class NSTextView. It is possible that this object was over-released, or is in the process of deallocation.
Run Code Online (Sandbox Code Playgroud)

默认情况下,XCode的出口也会创建为assign

为什么不能有弱参考?可能是什么原因?

macos cocoa objective-c nstextview

6
推荐指数
1
解决办法
687
查看次数

iOS13 UICollectionView不尊重单元格委托方法中返回的大小

在iOS13中,我返回

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
   return collectionView.bounds.size
}
Run Code Online (Sandbox Code Playgroud)

但是显示的单元格是水平拥抱的,不是全角...这之前没有发生

有什么变化是负责任的吗?为什么会这样呢?

cocoa-touch objective-c ios13

6
推荐指数
1
解决办法
144
查看次数

macOS NavigationStack 使用推送和弹出动画

如何在macOS中设置 Push/Pop 动画NavigationStack?因为目前没有动画,我想推送/弹出控制器向右滑动(向左滑动),类似于AppStore应用程序

enum Nav {
    case a
}

struct MainView: View {
  
    var body: some View {
        NavigationStack {
            NavigationLink(value: Nav.a) {
                Text("Go to a")
            }
            .navigationDestination(for: Nav.self) { path in
                switch path {
                case .a:
                    Text("a")
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

swiftui swiftui-animation swiftui-navigationstack

6
推荐指数
0
解决办法
225
查看次数