我正在深入了解并发性,并且已经广泛阅读了关于GCD和NSOperation.然而,许多帖子,如SO上的标准答案都已有几年了.
在我看来,过去的NSOperation主要优势是以某些性能为代价:
由于GCD的DispatchWorkItem&块取消/ DispatchGroup/ qos特别是有一个真正的激励(性价比明智)使用NSOperation时就开始执行或查询任务状态再从那里,你需要能够取消任务的情况下并发分开?
苹果公司似乎更加重视GCD,至少在他们的WWDC中(授予它更近NSOperation).
我试图通过cropping(to:)a 上的方法裁剪用 iPhone 相机拍摄的图像的一部分CGImage,但我遇到了一个奇怪的现象,在UIImage转换时我的尺寸加倍.cgImage,这显然阻止了我做我想做的事情。
流程是:
.image现在设置为“屏幕截图”let croppedImage = imageContainerView.renderToImage()
imageContainerView.image = croppedImage
print(imageContainerView.image!.size) //yields (320.0, 568.0)
print(imageContainerView.image!.cgImage!.width, imageContainerView.image!.cgImage!.height) //yields (640, 1136) ??
extension UIView {
func renderToImage(afterScreenUpdates: Bool = false) -> UIImage {
let rendererFormat = UIGraphicsImageRendererFormat.default()
rendererFormat.opaque = isOpaque
let renderer = UIGraphicsImageRenderer(size: bounds.size, format: rendererFormat)
let snapshotImage = renderer.image { _ in
drawHierarchy(in: bounds, afterScreenUpdates: afterScreenUpdates)
}
return snapshotImage
} …Run Code Online (Sandbox Code Playgroud) 在Xcode 9的GM版本中,我遇到了一些编译时错误undefined symbols for architecture arm64,即AVFoundation:
AVCapturePhotoOutput().supportedFlashModesAVCapturePhotoSettings().availablePreviewPhotoPixelFormatTypes在这两种情况下,使用他们的"无证件" __supportedFlashModes/ __availablePreviewPhotoPixelFormatTypes构建就好了.
我试图以一种优雅的方式实现以下行为:
users按id 重新排序userIds并过滤掉userid 不在的所有suserIds
试图以"Swifty方式"来做:
var users = [["id": 3, "stuff": 2, "test": 3], ["id": 2, "stuff": 2, "test": 3], ["id": 1, "stuff": 2, "test": 3]]
var userIds = [1, 2, 3]
userIds.map({ userId in users[users.index(where: { $0["id"] == userId })!] })
Run Code Online (Sandbox Code Playgroud)
产生重新排序和过滤的预期结果.但是当代码userIds包含一个不属于userin users(例如4)的id 时代码崩溃,这要归功于force-unwrap.
我失去了什么让它在没有崩溃的情况下工作?
仍然是一个 Swift 菜鸟,我一直在寻找一种正确的方法/最佳实践来管理我的UITableView(使用自定义UserCells)中的行删除,基于在using 委托中点击 a UIButton,UserCell这似乎是最干净的方法。
我跟着这个例子:UITableViewCell Buttons with action
我拥有的
UserCell 类
protocol UserCellDelegate {
func didPressButton(_ tag: Int)
}
class UserCell: UITableViewCell {
var delegate: UserCellDelegate?
let addButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Add +", for: .normal)
button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
addSubview(addButton)
addButton.rightAnchor.constraint(equalTo: self.rightAnchor, constant: -6).isActive = true
addButton.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive …Run Code Online (Sandbox Code Playgroud) 当按下按钮时,我似乎无法隐藏根视图控制器(A)中的状态栏.
我已在我的info.plist属性Status bar is initially hidden和View controller-based status bar appearance到YES.
如果我实现了override var prefersStatusBarHidden: Bool { get },状态栏将被明确隐藏(或不是).
我需要的
我希望状态栏显示在(A)中,但是当我按下将子视图控制器添加到(A)的按钮时隐藏状态栏.
我已经尝试设置prefersStatusBarHidden到false并使用其隐藏UIApplication.shared.isStatusBarHidden = true在按下按钮时,不过这是行不通的.
肯定有一些我错了,有人可以开导我吗?
提前致谢.
PS:我只需要它是隐形的,不一定是"隐藏"在Swift意义上.
ios ×5
swift ×5
swift3 ×2
arrays ×1
avfoundation ×1
cgimage ×1
dictionary ×1
nsoperation ×1
uibutton ×1
uikit ×1
uitableview ×1
xcode ×1
xcode9 ×1