我想实现与[[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) 如果我在已经构造的对象或结构上调用构造函数,它会分配新空间,还是只使用现有空间?那么第一个对象分配是否更加资源密集?像这样:
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(...) …
我在字典上使用了一个简单的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)
为什么在"引号"中有一些关键名称,有些则不是?
我需要计算给定日期的工作日,但是,根据日历,一周可以在星期一加星,在星期日看星期日
所以我想设置它,从周一开始,使用
[[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)
返回相同的数字,但为什么?
我想知道NSDictionary方法allKeys背后的决定是什么,返回一个NSArray,而不是NSSet,这将更有意义,因为不能保证返回数组的顺序,而且,一个键是唯一的
如何使用displatch_once,因此每个实例生命周期执行一次给定的代码
等价的是在对象中有一个属性,并像这样使用它
- (void)viewWillAppear:(..).. {
...
if (self.isDisplatched == NO) {
...
self.isDisplatched = YES;
}
}
Run Code Online (Sandbox Code Playgroud)
但我不想使用额外的属性,而是dispatch_once_t或simmilar
更新到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
我注意到比在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
为什么不能有弱参考?可能是什么原因?
在iOS13中,我返回
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return collectionView.bounds.size
}
Run Code Online (Sandbox Code Playgroud)
但是显示的单元格是水平拥抱的,不是全角...这之前没有发生
有什么变化是负责任的吗?为什么会这样呢?
如何在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) cocoa ×6
objective-c ×6
ios ×3
cocoa-touch ×2
nsdictionary ×2
nstextview ×2
allocation ×1
c++ ×1
constructor ×1
facebook ×1
ios13 ×1
macos ×1
memory ×1
nscalendar ×1
nsdate ×1
nstextfield ×1
swiftui ×1