ExclusivePrice,数量均为NSDecimalNumbers.
NSDecimalNumber *price = [exclusivePrice decimalNumberByMultiplyingBy:quantity];
NSLog(@"%@ * %@ = %@", exclusivePrice, quantity, price);
Run Code Online (Sandbox Code Playgroud)
结果我得到:
2010-04-05 00:22:29.111 TestApp[13269:207] 65 * 2 = -0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007169919476068871316457914368
Run Code Online (Sandbox Code Playgroud)
我的期望:
2010-04-05 00:22:29.111 TestApp[13269:207] 65 * 2 = 130
Run Code Online (Sandbox Code Playgroud)
有人能解释一下吗?
编辑:
完全重复:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSDecimalNumber *n2 = (NSDecimalNumber *)[formatter numberFromString:@"2"];
NSDecimalNumber *n1 = (NSDecimalNumber *)[NSDecimalNumber numberWithInt:65];
NSDecimalNumber *n3 = [n1 decimalNumberByMultiplyingBy:n2];
NSLog(@"%@ * %@ = %@", n1, n2, n3);
Run Code Online (Sandbox Code Playgroud) 我创建了一个OS/X应用程序,当它运行时,我将窗口定位在屏幕的中心.为了做到这一点,我必须在计算y值时包含标题栏高度.
有没有办法确定默认标题栏?我希望(基于我对其他窗口系统的经验)我必须以某种方式查询窗口管理器...
我正在尝试编写一个帮助程序类,以允许我们的应用程序支持UIAlertAction和UIAlertView.但是,在编写alertView:clickedButtonAtIndex:方法时UIAlertViewDelegate,我遇到了这个问题:我看不到在a的处理程序块中执行代码的方法UIAlertAction.
我试图通过UIAlertAction在一个名为的属性中保留一个s 数组来做到这一点handlers
@property (nonatomic, strong) NSArray *handlers;
Run Code Online (Sandbox Code Playgroud)
然后实现这样的委托:
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIAlertAction *action = self.handlers[buttonIndex];
if (action.enabled)
action.handler(action);
}
Run Code Online (Sandbox Code Playgroud)
但是,没有action.handler属性,或者确实有任何我可以看到的方法来获取它,因为UIAlertAction标题只有:
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>
+ (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(UIAlertAction *action))handler;
@property (nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) UIAlertActionStyle style;
@property (nonatomic, getter=isEnabled) BOOL enabled;
@end
Run Code Online (Sandbox Code Playgroud)
有没有其他方法来执行handler块中的代码UIAlertAction?
objective-c ios objective-c-blocks uialertviewdelegate uialertaction
我们正在离开MBProgressHUD,因为它在我们的应用程序中太麻烦了,并且没有阻止用户输入或提供取消按钮等功能.
那么,我试图在UIAlertController的中心实现Swipesight的如何显示活动指示器?,我遇到了指标的不正确定位:
objective-c
uiactivityindicatorview
ios
uialertcontroller
iOS和OS X NSNumberFormatterStyle枚举使用新的iOS 9和OS X 10.11 SDK获得了4个新值!它们听起来很酷且很有用,但Apple的文档,甚至谷歌都没有什么可说的!
传递给公式时这些新值的作用是什么,它们与旧值有什么不同?
在iOS 9.0或OS X 10.11中>框架>基础> NSNumberFormatter.h第46-57行:
typedef NS_ENUM(NSUInteger, NSNumberFormatterStyle) {
NSNumberFormatterNoStyle = kCFNumberFormatterNoStyle,
NSNumberFormatterDecimalStyle = kCFNumberFormatterDecimalStyle,
NSNumberFormatterCurrencyStyle = kCFNumberFormatterCurrencyStyle,
NSNumberFormatterPercentStyle = kCFNumberFormatterPercentStyle,
NSNumberFormatterScientificStyle = kCFNumberFormatterScientificStyle,
NSNumberFormatterSpellOutStyle = kCFNumberFormatterSpellOutStyle,
NSNumberFormatterOrdinalStyle NS_ENUM_AVAILABLE(10_11, 9_0) = kCFNumberFormatterOrdinalStyle,
NSNumberFormatterCurrencyISOCodeStyle NS_ENUM_AVAILABLE(10_11, 9_0) = kCFNumberFormatterCurrencyISOCodeStyle,
NSNumberFormatterCurrencyPluralStyle NS_ENUM_AVAILABLE(10_11, 9_0) = kCFNumberFormatterCurrencyPluralStyle,
NSNumberFormatterCurrencyAccountingStyle NS_ENUM_AVAILABLE(10_11, 9_0) = kCFNumberFormatterCurrencyAccountingStyle,
};
Run Code Online (Sandbox Code Playgroud) 我喜欢Objective-C中的这种语法:
NSString const name = [self getName] ?: @"backup";
Run Code Online (Sandbox Code Playgroud)
我想在Swift中使用相同的东西,但是当我尝试时我得到了这个:
在Swift中有什么办法吗?如果没有,我可以编写一个自定义的infox运算符吗?
if (flipped.charAt(0) = "a" || "e" || "i" || "o" || "u"){
paren = "(" + flipped;
String firstpart = paren.substring(0,5);
String rest = paren.substring(5);
System.out.println(rest+firstpart);
}
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我想检查String翻转的第一个字符是否是元音.如果是,我在开头添加一个括号,并将前5个字符移动到字符串的末尾.Eclipse正在给我java.lang.NullPointerException并说"分配的左侧必须是一个变量." 我该怎么做才能解决这个问题?
我正试图检查某个char元音是否是元音.这样做的最佳方法是什么?
我试图设置组件的可聚焦性,并找到了这两种方法,希望我可以使用它们使组件仅在用户触摸时才可聚焦,而不能通过编程方式请求:
myComponent.setFocusable(false);
myComponent.setFocusableInTouchMode(true);
Run Code Online (Sandbox Code Playgroud)
然后我查看了他们的文档:
public void setFocusable(布尔型可聚焦)
设置此视图是否可以接收焦点。将其设置为false还将确保该视图在触摸模式下无法聚焦。
public void setFocusableInTouchMode(布尔的focusableInTouchMode)
设置在触摸模式下此视图是否可以接收焦点。将其设置为true也将确保该视图可聚焦。
那么,如果隐式调用任何一个,则为什么要区分?
Swift有这个方便的语法:
enum Foo {
case bar
case baz
}
func hoge(foo: Foo) {
}
hoge(foo: .bar) // This
Run Code Online (Sandbox Code Playgroud)
哪个镜像在enums 以外的地方:
struct Qux {
static let `default` = Qux()
}
func hoge(qux: Qux) {
}
hoge(qux: .default) // This
Run Code Online (Sandbox Code Playgroud)
我不知道在谈话/门票中该怎么称呼它.也许"类型推断点语法"?我不确定.这个语法有官方名称吗?如果是这样,它是什么?
objective-c ×3
cocoa-touch ×2
ios ×2
java ×2
android ×1
android-view ×1
char ×1
cocoa ×1
enums ×1
focus ×1
foundation ×1
macos ×1
naming ×1
nswindow ×1
setfocus ×1
string ×1
swift ×1
swift2 ×1
syntax ×1