让我们假设我们有一个地图类(无序地图,列表,集合,也可以做任何事情).我们正在寻找一个特定的元素.在调用find()成员之后,我们必须检查end()成员.但是find()在内部已经知道它是返回一个好的迭代器还是结束迭代器.我们为什么还需要再次调用end()?这增加了一些开销.
std::map<int,float> myMap;
// some other code to populate the map
// ...
std::map<int,float>::iterator myIt;
myIt = myMap.find(2); // doesn't this already know wheter its returning the end() iterator?
if (myIt != myMap.end()) { //calling end() here wastes some time because find
//already knew the result
std::cout << "Found, value is "<<(*myIt).second<<"\n";
} else {
std::cout << "Not found.\n";
}
Run Code Online (Sandbox Code Playgroud)
应该有一种方法可以在不调用end()的情况下知道find()的结果.
我很难找出pushViewController是否保留了控制器,目前我有以下代码(有效)...
ColorController *colorController = [[ColorController alloc] initWithNibName:nibColor bundle:nil];
[[self navigationController] pushViewController:colorController animated:YES];
[colorController release];
Run Code Online (Sandbox Code Playgroud)
但我正在考虑删除发布并添加自动释放...
ColorController *colorController = [[[ColorController alloc] initWithNibName:nibColor bundle:nil] autorelease];
[[self navigationController] pushViewController:colorController animated:YES];
Run Code Online (Sandbox Code Playgroud)
非常感激
加里
男人最简单的东西在Objective-C中对我来说似乎总是那么疯狂,无论如何我需要做一些基本的减法和乘法而且难倒.
我有:
client.PricingDiscount <-- this is an Integer 16 property on a CoreData NSManagedObject
sku.RetailPrice <-- this is a Decimal property on a CoreData NSManagedObject
Run Code Online (Sandbox Code Playgroud)
我只是想让NSDecimalNumber像这样显示:
NSDecimalNumber *showPrice = sku.RetailPrice * (100 - client.PricingDiscount);
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一些不同形式的这个,无法弄清楚我到底做错了什么.
如何列出 Red Hat Linux 系统上链接到 libssl 的所有可执行文件?我可以接近:
find / -type f -perm /a+x -exec ldd {} \; | grep libssl
Run Code Online (Sandbox Code Playgroud)
ldd 显示了可执行文件链接到的库,但是包含库名称的行并不显示文件名,因此虽然我使用 grep 得到了很多匹配项,但我不知道如何返回该库的名称发生匹配的可执行文件。任何帮助将不胜感激。
我正在使用NSSearchField通过Internet运行查询并在表格视图中显示结果.在查询运行时,我想在NSSearchField中显示进度指示器?我想我以前在另一个应用程序中看到过这个.
是否有可用于实现此目的的开源组件?
我该怎么做呢?什么是最好的方法?有什么陷阱?
我有一个显示图像的 NSView,我想让这个视图像裁剪图像效果一样。然后,我让3个矩形(imageRect,secRect和IntersectRect)时,imageRect是显示图像的矩形,secRect是矩形这只是充当变暗整体imageRect,并且intersectRect是像一个观察的rect一个矩形,我想要做的是什么样的做一个“洞” 就secRect直接看到了imageRect(没有变暗)。这是我的 drawRect 方法:
- (void)drawRect:(NSRect)rect {
// Drawing code here.
NSImage *image = [NSImage imageNamed:@"Lonely_Tree_by_sican.jpg"];
NSRect imageRect = [self bounds];
[image compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver ];
if (NSIntersectsRect([myDrawRect currentRect], [self bounds])) {
//get the intersectionRect
intersectionRect = NSIntersectionRect([myDrawRect currentRect], imageRect);
//draw the imageRect
[image compositeToPoint:imageRect.origin operation:NSCompositeSourceOver];
//draw the secRect and fill it with black and alpha 0.5
NSRect secRect = NSMakeRect(imageRect.origin.x, imageRect.origin.y, …Run Code Online (Sandbox Code Playgroud) 有没有办法从函数中选择并让它返回递增的数字?
例如,执行以下操作:
SELECT SomeColumn, IncrementingNumbersFunction() FROM SomeTable
Run Code Online (Sandbox Code Playgroud)
让它回归:
SomeColumn | IncrementingNumbers
--------------------------------
some text | 0
something | 1
foo | 2
Run Code Online (Sandbox Code Playgroud) 我有一个IEnumerable的项类定义如下:
public class Item {
public DateTime Date { get; private set; }
public decimal? Value { get; private set; }
public Item(DateTime date, decimal? value) {
Date = date;
Value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
这些项目处于特定的时间间隔(例如5分钟).我需要按日期对它们进行分组,但需要更改间隔.例如,如果项目按以下顺序排列:
2010-08-24 00:05
2010-08-24 00:10
2010-08-24 00:15
2010-08-24 00:20
2010-08-24 00:25
2010-08-24 00:30
Run Code Online (Sandbox Code Playgroud)
我希望将它们分成15分钟的间隔,结果应如下所示:
2010-08-24 00:15
2010-08-24 00:30
Run Code Online (Sandbox Code Playgroud)
间隔由另一个类提供,但我可以得到表示该间隔的毫秒数(例如,Interval.FromMinutes(5).GetMilliseconds()应该返回300000).问题是如何编写一个分组函数,允许我做这样的事情:data = items.GroupBy(t => GroupingFunction(t.DateTime, interval))并获得结果?
更新:间隔不一定以分钟为单位.它可能是几小时,几分钟甚至几天.
是否有regsvr32的.NET或Win32版本?我想用代码注册一个COM DLL而不是shells到regsvr32程序.
objective-c ×4
cocoa ×2
iphone ×2
.net ×1
c ×1
c# ×1
c++ ×1
cocoa-touch ×1
group-by ×1
installation ×1
ldd ×1
linq ×1
linux ×1
macos ×1
nsimage ×1
regsvr32 ×1
sql-server ×1
stl ×1
t-sql ×1