gpt4 book ai didi

用C编写高度为2的决策树的简洁方法

转载 作者:行者123 更新时间:2023-12-02 08:50:19 24 4
gpt4 key购买 nike

我有一个高度为 2 的决策树:

const BOOL isVerticalAnimationRequired = YES;
const BOOL isArgumentEditorExpanded = YES;
const BOOL isSelectionLeftToRight = YES;

UITableViewRowAnimation argumentEditorAnimation;
if (isVerticalAnimationRequired)
{
argumentEditorAnimation = (isArgumentEditorExpanded) ? UITableViewRowAnimationTop : UITableViewRowAnimationBottom;
}
else
{
argumentEditorAnimation = (isSelectionLeftToRight) ? UITableViewRowAnimationLeft : UITableViewRowAnimationRight;
}

我的问题是代码冗长。理想情况下,我想在一个语句中声明和设置 argumentEditorAnimation

有没有聪明的 C 风格技巧来处理这种情况?

最佳答案

为了清楚起见,我想我不会尝试将其折叠成一个表达式,但如果您必须:

argumentEditorAnimation =
isVerticalAnimationRequired ?
(isArgumentEditorExpanded ?
UITableViewRowAnimationTop
: UITableViewRowAnimationBottom)
: (isSelectionLeftToRight ?
UITableViewRowAnimationLeft
: UITableViewRowAnimationRight);

或者,您可以在不需要时删除 {},从而使您的代码更加简洁。

(如果您想编写这些类型的表达式,请考虑使用较短的标识符。长标识符也会使代码冗长。例如,在您的 bool 值中删除 is。)

关于用C编写高度为2的决策树的简洁方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8944760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com