任何人都可以一步一步地向我解释这个功能吗?我的另一个代码不起作用,这就是为什么我认为我不理解这个功能。下面的代码是误解函数。
class MyView: NSView {
//add observer on awake from nib
//works fine
override func awakeFromNib() {
if let win = self.window {
win.addObserver(self, forKeyPath: Notification.Name.NSWindowDidBecomeKey.rawValue, options: .new, context: nil)
}
}
//remove observer on dealloc
//allso works fine
deinit {
if let win = self.window {
win.removeObserver(self, forKeyPath: Notification.Name.NSWindowDidBecomeKey.rawValue)
}
}
//never gets called
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
Swift.print(keyPath ?? "")
Swift.print("worked!")
}
override func draw(_ dirtyRect: NSRect) {
NSColor.blue.set()
NSBezierPath.fill(dirtyRect)
}
}

以下是我理解函数的方法(连接完成MS SQL)。不知道究竟是什么意思返回true,是否与sqlsrv_fetch_array相同?
<?php
public function sql_exec($query)
{
$query = trim($query);
if($this->result = db_query($query, $this->con_id))
{
$this->row_count = db_num_rows($this->result);
return TRUE; //what it returns exactly??
}
}
?>
&#13;
答案 0 :(得分:1)
<?php
public function sql_exec($query)
{
$query = trim($query);
if($this->result = db_query($query, $this->con_id))
{
$this->row_count = db_num_rows($this->result);
return TRUE; //what it returns exactly??
}
}
?>
如果查询成功执行,则上面的代码返回BOOLEAN值TRUE。但似乎在你给出的例子中没有调用该函数。