【发布时间】:2017-01-04 02:04:53
【问题描述】:
我刚开始学习 Swift,我一直在查阅 Apple 的开发指南,但是处理属性和指针时的一些语法让我很反感。苹果解释说属性只是使用点语法,甚至 API 似乎也反映了这一点,但它并没有达到我想要的效果。这是我一直在做的具体工作。我也在为实例初始化而苦苦挣扎。 我已经正确地创建了一个桥接头任何指导将不胜感激。谢谢!
这是我试图在 swift 中模拟的代码。
@property (nonatomic) SFWaterNode *waterSurface;
@property (nonatomic) NSTimeInterval lastUpdateTime;
@end
@implementation GameScene
- (void)didMoveToView:(SKView *)view {
self.backgroundColor = [SKColor blackColor];
CGPoint startPoint = CGPointMake(-1, self.size.height/2);
CGPoint endPoint = CGPointMake(self.size.width, self.size.height/2);
self.waterSurface = [SFWaterNode nodeWithStartPoint:startPoint endPoint:endPoint depth:self.size.height/2 color:[SKColor blueColor]];
[self addChild:self.waterSurface];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
[self.waterSurface splash:location speed:-50];
}
- (void)update:(CFTimeInterval)currentTime {
[self.waterSurface update:currentTime];
}
@end
【问题讨论】:
-
你真的应该学习 swift 的语法。
-
我知道一些 Swift - 我包含的代码是 Obj-C
-
好吧更简单的问题 - 这如何转化为 swift:@property (nonatomic) SFWaterNode *waterSurface;
-
那将是
public var waterSurface: SFWaterNode。在 Swift 中,属性只是一个变量。如果需要,您可以添加 get/set 方法,但不是必须的。 (我最终使用 didSet 比使用自定义设置器要多得多。)
标签: ios objective-c swift pointers properties