【发布时间】:2014-12-10 05:54:29
【问题描述】:
摘要:
自动生成的 -Swift.h 文件中有我的 Swift 类引用,但没有任何“func”定义。 (注意:我有其他 Swift 类的 funcs 列在 auto-gen 文件中并且工作得很好。)请你告诉我为什么这个其他类/func 在 Swift.h 文件中没有被正确描述
更多细节:
这是我自动生成的 .swift.h 文件。请注意,我的第一个名为“Shape”的类一切正常,您可以看到函数 defs 已为该类自动生成。然而,在我的另一个 swift 类“hiloBetFuncs”中,没有一个函数定义(只有一个 func)是自动生成的。因此,在我的 Objective-C 文件中,当我尝试在该类的实例上调用该函数时,当我在 Xcode 中键入时,无法识别出乐趣。
为什么 Swift 在 -Swift.h 中生成了类 ref 却省略了 func 定义。我也包括了下面的乐趣。
#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#pragma clang diagnostic ignored "-Wduplicate-method-arg"
@class nm_skin;
@class nm_theFeature;
SWIFT_CLASS("_TtC9Golf_Whiz5Shape")
@interface Shape : NSObject
- (NSString *)testFunction;
- (void)skinDetails:(nm_skin *)skinny feature:(nm_theFeature *)feature;
- (instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end
SWIFT_CLASS("_TtC9Golf_Whiz12hiloBetFuncs")
@interface hiloBetFuncs : NSObject
- (instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end
#pragma clang diagnostic pop
这是 hiloBetFuncs 类(和函数)本身。
import Foundation
class hiloBetFuncs : NSObject {
func hilo_updateAllBetsforHole ( var hole : Int, result : Int, arrayOfBets : [nm_bet]) -> Int {
var returnCodeValue : Int = 0
let numberOfBetsInArray = arrayOfBets.count
var previousHoleBetResult : Int
var newHoleBetResult : Int
// we are only dealing with 9-hole bets so if on the back nine, go ahead and drop the hole value
// by 9 so that we can use the same holes 0-9 regardless. (just makes things easier)
if hole > 8
{hole -= 9}
for bet in arrayOfBets {
if hole == 0 {
// hole 0 is a bit of a special case, just cause you are not building off the bet
// status from the previous hole. This hole will be an autonomous 0, 1, or -1
// just set it to the 'result' paramater that was sent in.
bet.holeResults[hole] = result;
println("after one hole, the primary bet has been updated with a status of \(result)");
} else {
//get pointer to the bet status as of the previous hole
previousHoleBetResult = bet.holeResults[hole - 1] as Int
//establish the bet status for the new hole, building from the previous hole's bet status
newHoleBetResult = previousHoleBetResult + result
// update the current hole's bet results with the newly calculated value
bet.holeResults[hole] = newHoleBetResult;
}
// we want to return the bet status from the last active bet - if 2 or -2 then calling function will know to start a new bet.
returnCodeValue = bet.holeResults[hole] as Int
}
println("ok, done the deed")
// since the home team could be 2 down, the bet status could be a negative number
// convert to abs before returning. Just checking for bet status, not care about who is leading.
return abs(returnCodeValue)
}
}
【问题讨论】:
-
nm_bet 是如何定义的?
-
nm_bet 是一个 objc 类,它被定义为 NSObject 的子类。这是一个非常简单的类,只有几个变量,没有方法。