也許我的標題是有點混亂,所以我會用一個場景如何使一個通用邏輯比較函數在ObjC
讓我們說,我想2個INT值之間進行比較,並返回我基於一個布爾值說明邏輯比較。
if (int1 > int2) return true;
if (int3 < int4) return true;
if (int5 == int6) return true;
if (int7 >= int8) return true;
if (int9 <= int10) return true;
但不是手工寫這個,我想這樣做
- (bool)compareVal1: (int)val1 withVal2: (int)val2 usingLogical: (NSString*)logic
{
if (val1 "logic" val2) return true;
}
我想它可以用來表示我想要的5邏輯比較一般的功能。 我不確定這是否可以實現,但如果您有任何其他解決方案,請告知:)