我正在使用自动创建的'ProjectName-Swift.h'文件在Objective-C中使用Swift类。不幸的是,每次编译时,我都会在此文件中出错:
// Generated by Swift version 1.0 (swift-600.0.34.4.8)
#if defined(__has_include) && __has_include(<swift/objc-prologue.h>)
# include <swift/objc-prologue.h>
#endif
#include <objc/NSObject.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
....
....
@interface UISoundBar : UIView
@property (nonatomic) NSInteger barNumber;
@property (nonatomic) UIColor * barColor;
@property (nonatomic) CGFloat barHeight;
@property (nonatomic) CGFloat barSpacing;
@property (nonatomic) NSArray * bars;
- (instancetype)initWithFrame:(CGRect)frame OBJC_DESIGNATED_INITIALIZER;
- (void)showBars;
- (void)setupBars;
@property (nonatomic) NSArray * bars.storage;
@end
我遗漏了一些其他生成的代码(...)错误发生在包含
的最后一行@property (nonatomic) NSArray * bars.storage
声明'属性有先前声明'和'缺失;'。删除此行后,一切正常。每次编译项目时都必须删除它,这只是一件麻烦事。有什么想法吗?
编辑:这是生成上述内容的原始swift类:
import Foundation
import UIKit
class UISoundBar : UIView {
var barNumber = 4
var barColor: UIColor = UIColor.redColor()
@lazy var barHeight:CGFloat = {
return (self.frame.height - CGFloat(self.barNumber) * self.barSpacing) / CGFloat(self.barNumber)
}()
var barSpacing:CGFloat = 0.4
@lazy var bars:UIView[] = {
var tempArr:UIView[] = []
for i in 1...self.barNumber {
var v = UIView(frame: CGRectMake(0, CGFloat(i - 1) * (self.barHeight + self.barSpacing), self.frame.size.width * 0.1, self.barHeight))
tempArr.append(v)
}
return tempArr
}()
init(frame: CGRect)
{
super.init(frame: frame)
}
func showBars()
{
for bar in self.bars{
self.addSubview(bar)
}
}
func setupBars()
{
for bar in self.bars {
bar.backgroundColor = self.barColor
}
}
}
答案 0 :(得分:0)
通过点语法声明属性,您想要完成什么?属性声明不允许你这样做,并且因为bars
已经被声明,这就是为什么它告诉你你正在尝试重新声明它。