我有一些让我感到困惑的东西,特别是下面的代码触发编译器错误"unresolved identifier self",我不知道为什么会发生这种情况,因为lazy意味着在使用该属性时,该类已经被实例化.我错过了什么吗?
提前谢谢了.
这是代码
class FirstClass {
unowned var second: SecondClass
init(second:SecondClass) {
self.second = second
print("First reporting for duty")
}
func aMethod() {
print("First's method reporting for duty")
}
}
class SecondClass {
lazy var first = FirstClass(second: self)
func aMethod() {
first.aMethod()
}
}
Run Code Online (Sandbox Code Playgroud) 我已经阅读了不同的解决方案,但似乎没有任何效果.此代码创建一个零异常:
[NSFontAttributeName: UIFont(name: "Raleway-SemiBold", size: 16)!]
Run Code Online (Sandbox Code Playgroud)
我正确安装了字体,它们在应用程序中正确显示(目标设置).
我尝试添加应用程序提供的字体plist但没有发生任何事情.我无法编辑数组中的项目:(they are item0 : string : Raleway-SemiBold.tff).
所以基本上我被卡住了......有时Swift和Apple环境对于程序员来说是很好的,有时候(大多数时候),它们太缺陷了,需要这么多的解决方法来达到预期的结果.
非常感谢您的帮助.
今天早上升级到8.3后,我在主题中收到错误.
下面的代码用于完美地工作,但它不再编译.你们有人可以帮助我吗?
protocol CustomAccessoryProtocol {
func controlButtonPressed(tag:Int)
}
class CustomAccessory : UIInputViewController {
var accessoryView : UIView!
var delegate : CustomAccessoryProtocol!
@IBOutlet weak var returnButton: UIButton!
@IBOutlet weak var backButton: UIButton!
@IBOutlet weak var forwardButton: UIButton!
init(delegate: CustomAccessoryProtocol){
super.init()
self.delegate = delegate
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
let customNib = UINib(nibName: "CustomAccessory", bundle: nil)
accessoryView = customNib.instantiateWithOwner(self, options: nil)[0] …Run Code Online (Sandbox Code Playgroud)
我有一个奇怪的问题.虽然我确实阅读了很多关于如何做到这一点的教程,但最终结果只显示了贝塞尔线,而不是任何阴影.我的代码非常简单:
let borderLine = UIBezierPath()
borderLine.moveToPoint(CGPoint(x:0, y: y! - 1))
borderLine.addLineToPoint(CGPoint(x: x!, y: y! - 1))
borderLine.lineWidth = 2
UIColor.blackColor().setStroke()
borderLine.stroke()
let shadowLayer = CAShapeLayer()
shadowLayer.shadowOpacity = 1
shadowLayer.shadowOffset = CGSize(width: 0,height: 1)
shadowLayer.shadowColor = UIColor.redColor().CGColor
shadowLayer.shadowRadius = 1
shadowLayer.masksToBounds = false
shadowLayer.shadowPath = borderLine.CGPath
self.layer.addSublayer(shadowLayer)
Run Code Online (Sandbox Code Playgroud)
我做错了什么,因为我似乎没有看到任何错误,但当然我错了,因为没有出现阴影.函数是drawRect,基本的UIVIew没有任何额外的东西,x和y是框架的宽度和高度.
提前谢谢了!