小编Ben*_*ero的帖子

NSDecimalNumber乘法奇怪

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)

cocoa-touch objective-c nsdecimalnumber

4
推荐指数
1
解决办法
5139
查看次数

如何获得NSWindow的默认标题栏高度?

我创建了一个OS/X应用程序,当它运行时,我将窗口定位在屏幕的中心.为了做到这一点,我必须在计算y值时包含标题栏高度.

有没有办法确定默认标题栏?我希望(基于我对其他窗口系统的经验)我必须以某种方式查询窗口管理器...

macos window-managers nswindow

4
推荐指数
3
解决办法
5449
查看次数

如何执行UIAlertAction的处理程序?

我正在尝试编写一个帮助程序类,以允许我们的应用程序支持UIAlertActionUIAlertView.但是,在编写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

4
推荐指数
1
解决办法
2621
查看次数

如何在UIAlertController中放置UIActivityIndi​​catorView?

我们正在离开MBProgressHUD,因为它在我们的应用程序中太麻烦了,并且没有阻止用户输入或提供取消按钮等功能.

那么,我试图在UIAlertController的中心实现Swipesight的如何显示活动指示器?,我遇到了指标的不正确定位:

一个<code>UIActivityIndicatorView</code>在<code>UIAlertController</code>白色矩形中保留空间</strong>,然后<strong>如何将其放在那里?</strong></p> </div>
        <p>
          <a href=objective-c uiactivityindicatorview ios uialertcontroller

4
推荐指数
1
解决办法
6920
查看次数

新的iOS9/OSX10.11 NSNumberFormatterStyle枚举值是什么意思?

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)

cocoa enums cocoa-touch foundation nsnumberformatter

4
推荐指数
1
解决办法
598
查看次数

我如何使用?:在Swift中?

我喜欢Objective-C中的这种语法:

NSString const name = [self getName] ?: @"backup";
Run Code Online (Sandbox Code Playgroud)

我想在Swift中使用相同的东西,但是当我尝试时我得到了这个:

<code> let name = getName()?:会导致编译器完全无法识别语法的错误">

在Swift中有什么办法吗?如果没有,我可以编写一个自定义的infox运算符吗?

ternary-operator infix-operator swift2

4
推荐指数
1
解决办法
2653
查看次数

为什么我的代码不会编译哪个字符串以元音开头检查?

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并说"分配的左侧必须是一个变量." 我该怎么做才能解决这个问题?

java string nullpointerexception

3
推荐指数
3
解决办法
5880
查看次数

检查字符是否是Java中的元音的最佳方法是什么?

我正试图检查某个char元音是否是元音.这样做的最佳方法是什么?

java char string-parsing

3
推荐指数
1
解决办法
7634
查看次数

为什么Android中有2个setFocusable方法?

我试图设置组件的可聚焦性,并找到了这两种方法,希望我可以使用它们使组件仅在用户触摸时才可聚焦,而不能通过编程方式请求:

myComponent.setFocusable(false);
myComponent.setFocusableInTouchMode(true);
Run Code Online (Sandbox Code Playgroud)

然后我查看了他们的文档

public void setFocusable(布尔型可聚焦)

设置此视图是否可以接收焦点。将其设置为false还将确保该视图在触摸模式下无法聚焦。


public void setFocusableInTouchMode(布尔的focusableInTouchMode)

设置在触摸模式下此视图是否可以接收焦点。将其设置为true也将确保该视图可聚焦。

那么,如果隐式调用任何一个,则为什么要区分?

android focus setfocus android-view

3
推荐指数
1
解决办法
2004
查看次数

什么是Swift语法".bar"?

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)

我不知道在谈话/门票中该怎么称呼它.也许"类型推断点语法"?我不确定.这个语法有官方名称吗?如果是这样,它是什么?

syntax naming swift

3
推荐指数
1
解决办法
269
查看次数