我正在尝试以编程方式在桌面上移动窗口。为此我尝试过:
let options = CGWindowListOption(arrayLiteral: .excludeDesktopElements, .optionOnScreenOnly)
let windowsListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
let windowsList = windowsListInfo as NSArray? as? [[String: AnyObject]]
let visibleWindows = windowsList?.filter{ $0["kCGWindowLayer"] as! Int == 0 }
for window in visibleWindows! {
let windowTitle = window["kCGWindowOwnerName"] as! String
let windowNumber = window["kCGWindowNumber"] as! Int32
if windowNumber == 124 { // Safari
let nsWindow = NSApp.window(withWindowNumber: Int(windowNumber))
nsWindow?.cascadeTopLeft(from: NSPoint(x: 100.0, y: 100.0))
nsWindow?.setFrameTopLeftPoint(NSPoint(x: 100.0, y: 100.0))
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试NSWindow使用时windowNumber:
NSApp.window(withWindowNumber: Int(windowNumber))
Run Code Online (Sandbox Code Playgroud)
我明白了 …
我有一个功能:
open func getAllCarsCount(from garages: [Garage], with categories: Set<Category> = []) -> Int {
var returnCount = 0
let context = DBContext.defaultContext
var predicates = [NSPredicate]()
for category in categories {
let predicate = NSPredicate(format: "SUBQUERY(carHasCategories, $c, $c.categoryName == %@ ).@count > 0", category.categoryName)
predicates.append(predicate)
}
for garage in garage {
let predicate = NSPredicate(format: "garageNbr = \(garage.garageNbr) AND active = 1" )
predicates.append(predicate)
}
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Car")
request.predicate = NSCompoundPredicate(orPredicateWithSubpredicates: predicates)
do {
let count = try …Run Code Online (Sandbox Code Playgroud) 实际上,我正在尝试获取所有打开的窗口列表,如下所示:
let options = CGWindowListOption(arrayLiteral: .excludeDesktopElements, .optionOnScreenOnly)
let windowsListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
let infoList = windowsListInfo as NSArray? as? [[String: AnyObject]]
Run Code Online (Sandbox Code Playgroud)
但这里的问题是,我还在状态栏上看到了Dockor Window Server、SystemUIServer或小部件。我怎样才能提高我的代码从这些因素得到避免,并获得唯一窗口列表,如Xcode,Finder等?
我的JSON看起来像:
{
"status": true,
"data": {
"img_url": "/images/houses/",
"houses": [
{
"id": "1",
"name": "Kapital",
"url": "https://kapital.com/",
"img": "10fbf4bf6fd2928affb180.svg"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用下一个结构:
struct ServerStatus: Decodable {
let status: Bool
let data: ServerData
}
struct ServerData: Decodable {
let img_url: String
let houses: [House]
}
struct House: Decodable {
let id: Int
let img: String
let name: String
let url: String
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用时:
let houses = try JSONDecoder().decode(ServerStatus.self, from: data)
Run Code Online (Sandbox Code Playgroud)
我收到下一个错误:
3 : CodingKeys(stringValue: "id", intValue: nil)
- debugDescription …Run Code Online (Sandbox Code Playgroud) func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if let cell = tableView.cellForRow(at: indexPath) as? ExpandablePlaneTableViewCell {
return 400.0
}
return 75.0
}
Run Code Online (Sandbox Code Playgroud)
我想改变我的细胞的大小,但heightForRowAt它内部看不到我的cell崩溃.当我放在那里if let检查它不进入块的内部,只需要75.
谁能告诉我这是什么问题?这对我来说太奇怪了!我已经将代表委托给了自己.所以它调用函数但无法在那里检测我的单元格.
UPDATE
在我的ExpandablePlaneTableViewCell我有一个变量:
var exapanded = false
Run Code Online (Sandbox Code Playgroud)
稍后在我的ViewController中:单击单元格中的按钮,我运行我的委托方法:
func expandViewButtonTapped(_ sender: ExpandablePlaneTableViewCell, for indexPath: IndexPath) {
sender.exapanded = true
tableView.reloadRows(at: [indexPath], with: .automatic)
}
Run Code Online (Sandbox Code Playgroud)
在我想扩展它并重新加载单元格之后
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "expandableCell", for: indexPath) as! ExpandablePlaneTableViewCell
cell.delegate …Run Code Online (Sandbox Code Playgroud) 当前,我有一个完成处理程序:
open func Start(completion: (() -> Void)) { ... }
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,我必须始终致电completion。我怎样才能使它成为可选的,所以在某些方法中我将使用completion块,而在另一些方法中,我将跳过它们而不添加到我的方法调用中?
例如,我想要与以下内容相同:
self.present(<#T##viewControllerToPresent: UIViewController##UIViewController#>, animated: <#T##Bool#>, completion: <#T##(() -> Void)?##(() -> Void)?##() -> Void#>)
Run Code Online (Sandbox Code Playgroud)
我试过了
open func Start(completion: (() -> Void)? = nil) { ... }
Run Code Online (Sandbox Code Playgroud)
添加问号,但是在这种情况下,我必须调用可选的完成块
completion?()
Run Code Online (Sandbox Code Playgroud)
我不能简单地打电话
start()
Run Code Online (Sandbox Code Playgroud)
我不需要在完成块中。需要我叫它