嘿,在一些类别上工作,我遇到了一个奇怪的问题,我基本上扩展了一个计算器类来添加一些trig方法,当我在返回时调用sin方法时,我得到的值不正确一双.我发送一个100.7的值到该方法,它返回0.168231,从我可以看到正确的值应该是= 0.939693或那里.
下面是代码,我还在这里附加了一个完整项目的链接:
(谢谢)
http://files.me.com/knyck2/svpfd4
//
// Calculator_trig.m
// 11.4_calculator_trig
//
// Created by Nicholas Iannone on 1/6/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "Calculator_trig.h"
#import <math.h>
@implementation Calculator (Trigonometry)
-(double) sin
{
double result;
result = (double) sin (accumulator);
return result;
}
-(double) cos
{
double result;
result = cos ( accumulator);
return result;
}
-(double) tan
{
double result;
result = tan ( accumulator);
return result;
}
@end
#import "Calculator.h"
@implementation Calculator
-(void) setAccumulator: (double) …Run Code Online (Sandbox Code Playgroud) 我有以下两种方法:
-(void)authenticateUserToGoogle:(NSString *)userName withPassword:(NSString *)password {
NSString *URLstr = GOOGLE_CLIENT_LOGIN;
URLstr = @"http://www.google.com/ig/api?stock=AAPL";
NSURL *theURL = [NSURL URLWithString:URLstr];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:theURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:100.0];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (!theConnection) {
NSLog(@"COuldn't register device information with Parking Server");
} else {
NSLog(@"Got a connection!!");
NSMutableData *_responseData = [NSMutableData data];
NSLog(@"respone_data = %@",_responseData);
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = [HTTPResponse statusCode];
if (404 == statusCode || 500 == …Run Code Online (Sandbox Code Playgroud) delegates objective-c nsurlconnection class-method instance-method
我为iphone编写了一个应用程序,我希望将其中的图像保存为default.png,以便进行下一次调用.这可能吗?似乎沙箱不允许您覆盖其本地文件系统中的任何内容.
因此,我的客户iphone应用程序已在过去几周内从5个左右的班级推迟到25个以上.有了这么大(对于iphone无论如何)的类结构,我一直在使用Singleton类来访问全局变量.问题是,每当我需要访问我正在处理的类之外的变量时,我可以选择修改代码以传递对变量的引用,或者只是将其抛入单例中.当然,将它放入单例中的代码和工作量要少得多,但是,现在单身人士开始看起来像是一个无关的全局变形.
我的问题是,维护一个具有不相关的全局变量的大型单例对象是多么合适,以及在"非平凡"的iphone应用程序中跨类共享数据的"最佳实践"方式通常是什么?
非常感谢您的建议!
我只是从Cassandra开始,我有一个特殊的问题,每当我检索一个值时,十六进制返回(请参见下文).我用Google搜索没有成功.我很感激任何可能提供的帮助.谢谢!
[default@MyKeyspace] set User['hirsch']['email'] = 'swhirsch@nyc.rr.com';
Value inserted.
[default@MyKeyspace] get User['hirsch']['email'];
=> (column=656d61696c, value=7377686972736368406e79632e72722e636f6d, timestamp=1292294713343000)
Run Code Online (Sandbox Code Playgroud) 我在自制程序代码库中找到以下代码:
reject{|arg| arg[0..0] == '-'}
Run Code Online (Sandbox Code Playgroud)
显然,如果元素以' - '开头,这将删除数组元素(self).我的问题是为什么你需要以这种方式指定arg的第0个元素,arg [0..0]而不是仅指定arg [0]?
我对木偶很新,只是想了解输出告诉我的内容.我有一个非常简单的init.pp文件来配置shudders文件:
class sudo {
package { sudo:
ensure => present,
}
if $operatingsystem == "Ubuntu" {
package { "sudo-ldap":
ensure => present,
require => Package["sudo"],
}
}
file { "/etc/sudoers":
owner => "root",
group => "wheel",
mode => 0440,
source => "puppet:///modules/sudo/sudoers",
require => Package["sudo"],
}
Run Code Online (Sandbox Code Playgroud)
但是每当我运行以下命令时:
sudo puppet agent --server=my-imac.local --no-daemonize --verbose --onetime --noop
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
info: Caching catalog for susan-hirschs-imac.local
info: Applying configuration version '1321294018'
notice: /Stage[main]/Sudo/Package[sudo]/ensure: current_value absent, should be present (noop)
notice: Class[Sudo]: Would have triggered 'refresh' …Run Code Online (Sandbox Code Playgroud) 好吧所以我决定学习python(perl,c,c ++,java,objective-c,ruby以及一些erlang和scala).当我尝试执行此操作时,我继续收到以下错误:
Tue Jul 21{stevenhirsch@steven-hirschs-macbook-pro-2}/projects/python:-->./apache_logs.py
File "./apache_logs.py", line 17
print __doc__
^
SyntaxError: invalid syntax
#!/usr/local/bin/python
"""
USAGE:
apache_logs.py
"""
import sys
import os
if __name__ == "__main__":
if not len(sys.argv) > 1:
print __doc__
sys.exit(1)
infile_name = sys.argv[1]
Run Code Online (Sandbox Code Playgroud)
我知道它一定是非常愚蠢的东西,但我用谷歌搜索并阅读文档而没有找到任何东西.所有文档似乎都表明我编码的内容应该有效.
非常感谢您的帮助!!
任何人都可以解释为什么在这里找到的示例iphone应用程序LocateMe中使用MyCLController类的单例实例
以及保留,retainCount,release和autorelease的覆盖?任何帮助将非常感谢!!
我一直试图在ruby中使用autovivification进行简单的记录合并:
2009-08-21|09:30:01|A1|EGLE|Eagle Bulk Shpg|BUY|6000|5.03
2009-08-21|09:30:35|A2|JOYG|Joy Global Inc|BUY|4000|39.76
2009-08-21|09:30:35|A2|LEAP|Leap Wireless|BUY|2100|16.36
2009-08-21|09:30:36|A1|AINV|Apollo Inv Cp|BUY|2300|9.15
2009-08-21|09:30:36|A1|CTAS|Cintas Corp|SELL|9800|27.83
2009-08-21|09:30:38|A1|KRE|SPDR KBW Regional Banking ETF|BUY|9200|21.70
2009-08-21|09:30:39|A1|APA|APACHE CORPORATION|BUY|5700|87.18
2009-08-21|09:30:40|A1|FITB|Fifth Third Bancorp|BUY|9900|10.86
2009-08-21|09:30:40|A1|ICO|INTERNATIONAL COAL GROUP, INC.|SELL|7100|3.45
2009-08-21|09:30:41|A1|NLY|ANNALY CAPITAL MANAGEMENT. INC.|BUY|3000|17.31
2009-08-21|09:30:42|A2|GAZ|iPath Dow Jones - AIG Natural Gas Total Return Sub-Index ETN|SELL|6600|14.09
2009-08-21|09:30:44|A2|CVBF|Cvb Finl|BUY|1100|7.64
2009-08-21|09:30:44|A2|JCP|PENNEY COMPANY, INC.|BUY|300|31.05
2009-08-21|09:30:36|A1|AINV|Apollo Inv Cp|BUY|4500|9.15
Run Code Online (Sandbox Code Playgroud)
所以例如我希望A1 AINV BUY 9.15的记录总共有6800.这是使用自动修复的完美问题.继承我的代码:
#!/usr/bin/ruby
require 'facets'
h = Hash.autonew
File.open('trades_long.dat','r').each do |line|
@date,@time,@account,@ticker,@desc,@type,amount,@price = line.chomp.split('|')
if @account != "account"
puts "#{amount}"
h[@account][@ticker][@type][@price] += amount
end
#puts sum.to_s
end …Run Code Online (Sandbox Code Playgroud) 从命令行执行perl脚本时,如何确保输出不会从屏幕滚动?
换句话说,我如何模仿unix"更多"或"更少"命令的功能?
在应用程序中实现实时设备到设备通信的最佳方法是什么?我一直在尝试使用Apple推送通知服务,但发现它最适合实时消息传递.有没有办法利用套接字或我只是坚持使用APNS?
我有一个tableview活动作为设置或首选项面板(见下文).设置的名称(例如地址)是设置所属部分的标题.我的问题是,如果我想允许用户添加她自己的设置应该如何做?我想在工具栏上添加一个"+"按钮,弹出一个模态视图控制器,询问新的设置细节.我的问题是,是否有一种方法可以直接将设置添加到设置视图,而不是弹出模态视图控制器.因此,按"+"将使用文本字段展开下面显示的视图,以输入新设置的详细信息.
alt text http://www.freeimagehosting.net/uploads/634bb426be.png
iphone ×4
objective-c ×4
ruby ×2
singleton ×2
arrays ×1
calculator ×1
cassandra ×1
class ×1
class-method ×1
delegates ×1
get ×1
hex ×1
image ×1
indexing ×1
oop ×1
perl ×1
puppet ×1
python ×1
sandbox ×1
screen ×1
settings ×1
syntax-error ×1
trigonometry ×1
uitableview ×1
xcode ×1