我在我的自定义UIView的drawRect中绘制了一个圆圈:
- (void)drawRect:(CGRect)rect {
...
UIBezierPath *ovalPath = [UIBezierPath bezierPathWithOvalInRect:rect];
[UIColor.whiteColor setStroke];
ovalPath.lineWidth = 1;
[ovalPath stroke];
}
Run Code Online (Sandbox Code Playgroud)
椭圆形总是夹在边缘上.我怎样才能避免剪辑?是唯一的方法是插入矩形吗?
我创建了一个不同的init方法,并希望它是指定的初始化程序而不是标准-init.如何防止客户端代码使用实例化类-init?
例如
/* everyone must call this */
- (id)initWithInfo:(NSDictionary *)info {
self = [super init];
if (self) {
_info = info;
}
return self;
}
/* Don't want anyone to be able to create this using init */
Run Code Online (Sandbox Code Playgroud) 在 Swift 中,如何创建一个包含捕获列表和参数的闭包?
我使用过以任何一种形式呈现的代码,但不知道如何创建具有参数和捕获列表的闭包。
例如
关闭参数列表:
myFunction {
(x: Int, y: Int) -> Int in
return x + y
}
Run Code Online (Sandbox Code Playgroud)
关闭捕获列表:
myFunction { [weak parent = self.parent] in print(parent!.title) }
Run Code Online (Sandbox Code Playgroud)
使用捕获列表的示例尝试:
class MyTest {
var value:Int = 3
func myFunction(f: (x:Int, y:Int) -> Int) {
print(f(x: self.value, y: 5))
}
func testFunction() {
myFunction {
[weak self] (x, y) in //<--- This won't work, how to specify weak self here?
print(self.value)
return self.value + y
}
}
}
Run Code Online (Sandbox Code Playgroud) Swift编程语言提到使用isEmpty来检查空字符串.是否存在检查字符串与""不会产生与使用isEmpty相同的结果的情况?
换一种说法:
if str.isEmpty {
XCTAssert(str == "", "This should be true as well")
}
Run Code Online (Sandbox Code Playgroud)
从文档:
通过检查其布尔值isEmpty属性,确定String值是否为空:
if emptyString.isEmpty {
print("Nothing to see here")
}
Run Code Online (Sandbox Code Playgroud) objective-c ×2
swift ×2
closures ×1
drawrect ×1
initializer ×1
ios ×1
parameters ×1
string ×1
swift2 ×1
uibezierpath ×1
uikit ×1