这是Swift中的有效代码:
println(nil < 1)
Run Code Online (Sandbox Code Playgroud)
同样,输出也是如此
println(nil > 1)
Run Code Online (Sandbox Code Playgroud)
将为false(数字1是任意的,您可以对-1执行相同操作,可能还有其他内容).我问的原因是因为我看到一些代码试图与"some_string".toInt()数值进行比较并编译,考虑到toInt()返回似乎是错误的Int?.
我的问题是,这应该是Swift中的有效语法吗?如果是这样,nil的数值是多少?
Swift 3.0更新:
看起来Swift Evolution通过删除可选的比较运算符解决了这个问题.这不再是Swift 3.0中的一个问题,因为它不能编译.
我尝试使用以下方法设置具有AutoLayout约束的视图constraintEqualToAnchor():
override func viewDidLoad() {
super.viewDidLoad()
let myView = UIView()
myView.backgroundColor = UIColor.orangeColor()
myView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(myView)
myView.leftAnchor.constraintEqualToAnchor(view.leftAnchor).active = true
myView.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor).active = true
myView.topAnchor.constraintEqualToAnchor(view.topAnchor).active = true
myView.bottomAnchor.constraintEqualToAnchor(view.bottomAnchor).active = true
/******************************************/
/* I try to change one of the constraints */
/******************************************/
myView.leftAnchor.constraintEqualToAnchor(view.rightAnchor, constant: -100).active = true
}
Run Code Online (Sandbox Code Playgroud)
在最后一行代码中,我尝试更改其中一个约束.我认为它会工作,但它在控制台日志中给出了一些错误
"<NSLayoutConstraint:0x7fb53a5180d0 H:|-(0)-[UIView:0x7fb53a5190b0](LTR) (Names: '|':UIView:0x7fb53a519240 )>",
"<NSLayoutConstraint:0x7fb53a51f660 H:[UIView:0x7fb53a519240]-(-100)-[UIView:0x7fb53a5190b0](LTR)>",
"<NSLayoutConstraint:0x7fb53a711ee0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fb53a519240(414)]>"
Run Code Online (Sandbox Code Playgroud)
使用时constraintEqualToAnchor()?,在设置约束后,更改约束的正确方法是什么?
我正在尝试创建一个带有表的托盘弹出式应用程序,该应用程序与Dropbox的弹出式视图中的一个非常相似。有一个文件表,当您将鼠标悬停在表格单元格上时,该单元格将突出显示并显示其他控件。我不确定NSTableView是否完全适合此操作?有人有建议吗?
我这里有这个代码......
#import <Foundation/Foundation.h>
#import "Chip.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Chip *chip = [[Chip alloc] init];
[chip release]; //Chip should be gone
NSLog(@"%@", chip);
[pool drain];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么在芯片发布后打印出来仍然给我描述.此时是否应该删除?
我定义了一个像这样的网格视图:
let lb01 = NSTextField(labelWithString: "01")
....
let gridView = NSGridView(views:
[ [empty, lb01],
[empty, lb02],
[lb03, lb04]
])
gridView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(gridView)
let layoutViewMap = ["another View": anotherView, "GridView": gridView]
var constraintList = [NSLayoutConstraint]()
let constraintV = NSLayoutConstraint.constraints( withVisualFormat: "V:[GridView]-50-[anotherView]", options: [], metrics: nil, views: layoutViewMap)
constraintList += constraintV
let constraintH = NSLayoutConstraint.constraints( withVisualFormat: "|-20-[GridView(==300)]", options: [], metrics: nil, views: layoutViewMap)
constraintList += constraintH
NSLayoutConstraint.activate(constraintList)
Run Code Online (Sandbox Code Playgroud)
在某些情况下,网格视图的高度会增加
我可以定义一个明确的高度
let constraintV = NSLayoutConstraint.constraints( withVisualFormat: "V:[GridView(==70)]-50-[anotherView]", options: [], metrics: nil, views: layoutViewMap) …Run Code Online (Sandbox Code Playgroud) swift ×3
autolayout ×2
cocoa ×2
ios ×1
macos ×1
memory-leaks ×1
mouseover ×1
objective-c ×1
optional ×1
uiview ×1