我目前正在学习Objective C,到目前为止我一直在使用自动引用计数和我的所有项目.然而,在与一些同事交谈之后,在网上查看了一些论坛后,我注意到了一种趋势,即关闭自动引用计数并手动管理内存.
我一直想知道ARC是否做得足够好,或者偶尔会丢球.手动分配/释放内存更有效吗?有些人会关闭ARC,因为这是他们习惯的吗?
我应该继续使用ARC吗?如果没有,是否有人知道未来ARC将足够好用的地方?
所以我一直在使用这个select声明:
select runners.name, runners.age, sum(races.laptime) as totallaptime
from runners join races on runners.runnerid = races.runnerid
where runners.region = "region001"
group by runners.runnerid
Run Code Online (Sandbox Code Playgroud)
这列出了来自特定区域的所有跑步者,并总计了他们所有的单圈时间.
不幸的是,这错过了该地区所有没有单圈时间的选手(可能是因为他们在races数据库中没有条目).
如何调整此select语句以使其包含特定区域中的所有运行程序0,totallaptime如果races数据库中没有任何条目,则列出for ?
(对不起,对于模糊的问题标题,我想不出任何总结这个问题的方法)
TIA
作为一个Javascript程序员,它已被打入我的脑袋,===而不是==尽可能使用.
当我学习Objective C时,即使在官方文档中,我也只看到==被使用.
我的问题是,我是否应该继续在Objective C代码中使用严格相等的习惯?它是否与Javascript一样必要?我认为严格的平等会略微提升性能,但是在Objective C中,这种提升太小而不能产生太大影响吗?
我在获取高度和宽度的准确读数时遇到问题.所以我制作了这个快速而又脏的应用来测试这种情况.
这是代码:
@interface wwfpViewController ()
@property (nonatomic, strong) UIView * box;
@property (nonatomic, strong) UILabel * info;
@end
@implementation wwfpViewController
@synthesize box,info;
- (void)viewDidLoad {
[super viewDidLoad];
box=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[box setBackgroundColor:[UIColor darkGrayColor]];
[box setAutoresizesSubviews:YES];
[box setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
info=[[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 300)];
[info setTextColor:[UIColor whiteColor]];
[info setBackgroundColor:[UIColor blackColor]];
[info setLineBreakMode:NSLineBreakByWordWrapping];
[info setNumberOfLines:10];
[info setText:@"..."];
[self.view addSubview:box];
[box addSubview:info];
[self updateInfo];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateView:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
}
- (void) updateInfo {
CGFloat selfHeight=self.view.frame.size.height;
CGFloat …Run Code Online (Sandbox Code Playgroud) 所以我有这个音频标签:
<audio src=".....mp3" autoplay id="aud"></audio>
Run Code Online (Sandbox Code Playgroud)
20秒后,我触发了这段代码:
var obj=$('#aud')
obj[0].volume=0;
obj[0].pause();
obj.prop('volume',0);
obj.trigger('pause');
obj.attr('src','');
obj.remove();
console.log('REMOVED!!');
Run Code Online (Sandbox Code Playgroud)
但是毕竟,音频仍在播放吗?
音频标签已成功被删除obj.remove(),但音频仍在继续。
在console.log()正确的记录。我没有错误。但是,尽管使用了多种方法来静音,暂停和删除音频标签,但音频仍会继续播放。
谁能解释为什么?
我需要用盐和火焰清除此音频。任何帮助将不胜感激,这正使我发疯……
我有类似这个问题的问题,但那里的答案没有帮助我.
我有这些代码行:
var id = item["id"] as? String ?? ""
var name = item["name"] as? String ?? ""
var pic = item["pic"] as? String ?? ""
Run Code Online (Sandbox Code Playgroud)
对我来说,这些代码行几乎相同.对于Xcode,这是另一回事.
第一行很好.后两行产生此错误:
'(key: AnyObject, value: AnyObject)' does not have a member named 'subscript'
Run Code Online (Sandbox Code Playgroud)
这里有一些更适合你的背景:
class func getFromJson(json:NSDictionary) -> [Collection] {
var collections = [Collection]()
if json.count > 0 {
for item in json {
var id = item["id"] as? String ?? ""
var name = item["name"] as? String ?? ""
var pic …Run Code Online (Sandbox Code Playgroud) 我正在关注此页面上的教程:
我在代码中达到了这一点:
let dict = ["list":list]
let lcH = NSLayoutConstraint.constraintsWithVisualFormat("H:[list(100)]", options: NSLayoutFormatOptions(0), metrics: nil, views: dict)
Run Code Online (Sandbox Code Playgroud)
最后一行产生了这个错误(箭头指向dict):
'String' is not identical to 'NSObject'
Run Code Online (Sandbox Code Playgroud)
我最初试图将本教程中的Objective C代码转换为Swift,我在同一个地方得到了完全相同的错误.那时我认为这是我错误地转换代码的结果,但现在我正在遵循这个Swift教程并得到完全相同的结果.
谁能让我知道我做错了什么?
我想尝试做以下事情:
UPDATE table SET fieldA='valueA' WHERE id='id1', SET fieldB='valueB' WHERE id='id2';
Run Code Online (Sandbox Code Playgroud)
但似乎无法让它发挥作用.有没有办法做到这一点,还是需要使用两个单独的SQL命令?
我整个星期都在添加点击手势识别器,但是我去做这个,就像我做了所有其他人一样,我的应用程序崩溃了.我一定是在遗漏一些东西,但对于我的生活,我找不到它是什么.我已经通过了十几篇关于这个bug的SO文章,但没有任何帮助.
这段代码:
@interface wwfpViewController ()
@property (nonatomic, strong) UIView * firstScreen;
@end
@implementation wwfpViewController
@synthesize firstScreen;
- (void)viewDidLoad {
[super viewDidLoad];
firstScreen=[[UIView alloc] initWithFrame:self.view.frame];
[firstScreen setBackgroundColor:[UIColor redColor]];
[self.view addSubview:firstScreen];
UITapGestureRecognizer * tap=[[UITapGestureRecognizer alloc] initWithTarget:firstScreen action:@selector(onTap:)];
[tap setNumberOfTapsRequired:1];
[firstScreen addGestureRecognizer:tap];
}
- (void) onTap:(UIGestureRecognizer*) recogniser {
NSLog(@"tap: %@",recogniser);
}
@end
Run Code Online (Sandbox Code Playgroud)
生成此错误:
2013-08-01 12:50:11.027 tyrionSwipe[27336:11303] -[UIView onTap:]: unrecognized selector sent to instance 0xe52c4a0
2013-08-01 12:50:11.029 tyrionSwipe[27336:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView onTap:]: unrecognized selector sent to instance …Run Code Online (Sandbox Code Playgroud) 我有一组不同类的实例(准确地说是9个),它们都具有相同的方法和属性,但每个都执行特定的任务.
我希望能够在任何时候在这些不同的对象之间切换.有时可能只使用少数几个对象,有时候当它们都被使用时,有时候只使用一个.
理想情况下,我想要一个可以指向任何这些对象的实例的单个属性.我尝试过这样的事情:
@property (nonatomic, strong) id * currentObj;
...
currentObj=[[ClassType3 alloc] init];
Run Code Online (Sandbox Code Playgroud)
(ClassType3仅仅是9个不同的类别中的一个,在本例中它们从去ClassType1到ClassType9)
但这不起作用,我得到这两个警告:
Property with 'retain (or strong)' attribute must be of object type.
Pointer to non-const type 'id' with no explicit ownership.
Run Code Online (Sandbox Code Playgroud)
我的问题是,可以实现这样的事情,还是我需要创建每个类的实例以防万一需要使用它?
objective-c ×4
sql ×2
swift ×2
audio ×1
autolayout ×1
cgrect ×1
class ×1
cocoa-touch ×1
dimensions ×1
equality ×1
html5 ×1
html5-audio ×1
ios ×1
javascript ×1
jquery ×1
mysql ×1
orientation ×1
properties ×1
select ×1
sql-update ×1