Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 正在尝试获取textView macOS的插入点_Cocoa_Nstextview - Fatal编程技术网

Cocoa 正在尝试获取textView macOS的插入点

Cocoa 正在尝试获取textView macOS的插入点,cocoa,nstextview,Cocoa,Nstextview,我正在尝试获取textView macOS的插入点 // Get insertion point position if let selectedRange = textView.selectedRange { cursorPosition = textView.offset(from: textView.beginningOfDocument, to: selectedRange.start) } 我得到这个错误

我正在尝试获取textView macOS的插入点

// Get insertion point position
            if let selectedRange = textView.selectedRange {
                cursorPosition = textView.offset(from: textView.beginningOfDocument, to: selectedRange.start)
            }
我得到这个错误:

条件绑定的初始值设定项必须具有可选类型,而不是 “NSRange”aka“\u NSRange”

我在iOS中使用了一个类似的代码,它可以工作,我做错了什么?

如果让我们假设任务的右侧是可选的。selectedRange不返回可选值;您应该能够直接使用它,而无需测试它