我需要迭代从结尾到beginnig的向量."正确"的方式是
for(std::vector<SomeT>::reverse_iterator rit = v.rbegin(); rit != v.rend(); ++rit)
{
//do Something
}
Run Code Online (Sandbox Code Playgroud)
当doSomething涉及了解实际索引时,需要使用rit进行一些计算以获得它,就像 index = v.size() - 1 - (rit - v.rbegin)
如果无论如何都需要索引,那么我坚信最好使用该索引进行迭代
for(int i = v.size() - 1; i >= 0; --i)
{
//do something with v[i] and i;
}
Run Code Online (Sandbox Code Playgroud)
这会发出一个i已签名v.size()且未签名的警告.改为
for(unsigned i = v.size() - 1; i >= 0; --i) 在功能上是错误的,因为这实际上是一个无限循环 :)
什么是美学上很好的方式来做我想做的事情
我希望我不是在寻找不存在的东西:)
因此,viewDidUnload从iOS 6开始不推荐使用,我现在需要做什么?
删除它,并将其中的所有内容迁移didReceiveMemoryWarning或保留,并且不执行任何操作didReceiveMemoryWarning?
我需要__bridge在iOS 上提供一些建议.
希望在SSCCE 1下面会解释这个问题比我的话比较好,但我需要知道我可以转换void*成NSMutableArray*; __bridge应该使用哪种变体(参见代码中的注释).
阅读不同的桥梁,我推断出我需要,__bridge_transfer但后来我收到了一个EXC_BAD_ACCESSaddObject:
最终,我想CGPoints在CGPath之后CGPathApply调用一个数组.
#import <Foundation/Foundation.h>
void _processPathElement(void* info, const CGPathElement* element)
{
NSMutableArray *array = (/* WHAT BRIDGE HERE */ NSMutableArray*) info;
switch (element->type)
{
case kCGPathElementMoveToPoint:
case kCGPathElementAddLineToPoint:
{
CGPoint point = element->points[0];
[array addObject:[NSValue valueWithCGPoint:point]];
break;
}
default:
break;
}
}
int main(int argc, char *argv[])
{
@autoreleasepool
{
//Create path
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint( path, …Run Code Online (Sandbox Code Playgroud) 我收到上面的错误,但不确定如何修复它.这是我的代码:
.H:
#import <UIKit/UIKit.h>
@protocol ColorLineDelegate <NSObject>
-(void)valueWasChangedToHue:(float)hue;
@end
@interface ColorLine : UIButton {
id <ColorLineDelegate> delegate;
}
@property (nonatomic, assign) id <ColorLineDelegate> delegate;
@end
Run Code Online (Sandbox Code Playgroud)
.M:
#import "ColorLine.h"
@implementation ColorLine
@synthesize delegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
错误发生在合成行中.我找不到问题了.
*由于未捕获的异常'NSInvalidUnarchiveOperationException'终止应用程序,原因:'* - [NSKeyedUnarchiver decodeObjectForKey:]:无法解码类的对象(NSLayoutConstraint)'
我有一个非常简单的应用程序
一个视图有一个按钮
I Control单击并将按钮拖动到第二个视图并选择MODAL
当我在模拟器中运行它时,一切正常
当我在运行iOS 5.1.1的iPad上运行时,它会因上面的错误而崩溃.我不知道为什么,也没有代码.
我在IB中有一个UIView,其中有另一个UIView,我用它作为容器视图.在代码中,我创建了三个不同的视图,然后根据应用程序的状态将相应的视图设置为容器视图中的动画.在任何给定时间,三种不同视图中只有一种是有效的.问题是,当我在模拟器中运行不同的iPhone时,我的新子视图不会缩放以匹配容器视图.我正在使用autolayout.出于测试目的,我将我的子视图设置为一个大按钮,它的所有边缘都限制在超视图中.并且容器视图的边缘也受限于它的超视图.我想要的是子视图匹配容器的视图.即按钮拉伸容器视图的整个大小.当在不同的iPhone上运行时,容器视图的大小以及子视图应该相对于不同的iPhone屏幕大小按比例缩放.
下面是我用来初始化子视图并设置相对于容器视图的约束的代码.
UIView *containerView = self.subView;
UIView *newSubview = [[mySubview alloc] init];
[newSubview setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.containerView addSubview:newSubview];
[self.containerView addConstraint:[NSLayoutConstraint constraintWithItem:newSubview attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.containerView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]];
[self.containerView addConstraint:[NSLayoutConstraint constraintWithItem:newSubview attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.containerView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0]];
[self.containerView addConstraint:[NSLayoutConstraint constraintWithItem:newSubview attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.containerView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0]];
[self.containerView addConstraint:[NSLayoutConstraint constraintWithItem:newSubview attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.containerView attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0]];
Run Code Online (Sandbox Code Playgroud)
我似乎无法让这个工作.我对autolayout很新,我不确定我做错了什么,并且想停止撞到这堵墙.任何帮助都会很棒.:)
*************附加信息**************
对不起,我没有尽可能清楚地说出我的问题.所以这里有更多关于屏幕截图的信息.首先,我将描述我在代码方面做了什么.
在AppDelegate.m中的didFinishLaunchingWithOptions中,我创建了这样的MyViewController,
self.myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
Run Code Online (Sandbox Code Playgroud)
在MyViewController.m中的viewDidLoad中,我创建了mySubview并将其添加到我的containerView并为此创建约束,
UIView *containerView = self.containerView;
UIView *mySubview = [[MySubview alloc] init];
[mySubview setTranslatesAutoresizingMaskIntoConstraints:NO];
[containerView addSubview:mySubview];
NSDictionary *views = …Run Code Online (Sandbox Code Playgroud) MPMediaPickerController 用于给出在iOS 8.4之前选择项目的可视指示.
在8.4显示选择器并allowsPickingMultipleItems设置为true时,它确实显示项目被选中mediaPicker:didPickMediaItems但在选择时,所选项目只是突出显示(有时),但然后只需翻转回正常显示而不突出显示+指示符.
我的项目中有3个配置(Debug,Distribution_AdHoc和Distribution_AppStore).在Xcode 3中,我们有一个列表,可以在构建和运行之前选择设备,版本,配置和目标.现在使用Xcode 4,我们在此列表中只有设备类型和版本.这带来了我的两个问题:
那么在哪里定义使用的配置?是"Project> Info>命令行构建中使用:Debug"定义的配置吗?
现在"项目"菜单被"产品"替换所以我们在哪里可以创建(或复制和编辑)配置?
谢谢.
I'm using NSYearCalendarUnit NSMonthCalendarUnit NSDayCalendarUnit but unfortunately, these "Calendar Units" are reported as deprecated first in IOS 8.0.
What's the alternative of them, or how do I avoid these warnings.
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
Run Code Online (Sandbox Code Playgroud) 在Rails代码中,人们倾向于使用Enumerable #injection方法来创建哈希,如下所示:
somme_enum.inject({}) do |hash, element|
hash[element.foo] = element.bar
hash
end
Run Code Online (Sandbox Code Playgroud)
虽然这似乎已成为一种常见的习语,但是有没有人看到优于"天真"版本的优势,这将是:
hash = {}
some_enum.each { |element| hash[element.foo] = element.bar }
Run Code Online (Sandbox Code Playgroud)
我在第一个版本中看到的唯一优势是你在一个封闭的块中执行它并且你没有(显式地)初始化哈希.否则它会以一种意想不到的方式滥用方法,难以理解并且难以阅读.那为什么它如此受欢迎?