我正在尝试编写一个程序来扫描可用的串行端口并在弹出菜单中显示它们.为什么我不能CFString从IORegistryEntryCreateCFProperty()函数中取直接并在下一行通过字符串插值将其添加到菜单中?由于某种原因,我的变量声明遇到错误:
"NSString不是CFString的子类型".
import Foundation
import Cocoa
import IOKit
import IOKit.serial
@objc class Serial {
init() {
}
@IBOutlet var serialListPullDown : NSPopUpButton!
func refreshSerialList(defaultprompt: String) {
let masterPort: mach_port_t = kIOMasterPortDefault
let classesToMatch: CFDictionary = IOServiceMatching(kIOSerialBSDServiceValue).takeUnretainedValue()
var matchingServices: io_iterator_t = 0
// remove everything from the pull down list
serialListPullDown?.removeAllItems()
// ask for all the serial ports
let kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, &matchingServices)
if kernResult == KERN_SUCCESS {
// success
while (io_object_t() == IOIteratorNext(matchingServices)) {
var …Run Code Online (Sandbox Code Playgroud) 我正在编写一个OS X应用程序,它通过串行连接与Arduino UNO交互.它目前从UNO读取字符串没有问题,但我无法设置在传出字符串上发送正确的换行符和回车符.
负责发送字符串的代码如下:
@IBAction func SendCommand(sender: AnyObject) {
let data = self.sendTextField.stringValue.dataUsingEncoding(NSUTF8StringEncoding)
self.serialPort?.sendData(data)
}
Run Code Online (Sandbox Code Playgroud)
目前我尝试在程序运行时在消息末尾手动插入'\ r \n'.这不应该等同于Arduino IDE在其自己的串行监视器中以编程方式进行的操作吗?但是我的应用程序没有将这些命令解释为Carriage-Return字符的Newline.它是否只能以编程方式进行,如果可以,如何进行?
先感谢您!
我目前有一个包含2行自定义单元格的UITableView.我最近在我的故事板上添加了第二个原型单元,并且一直试图将它添加到我的UITableView中但没有成功.我的cellForRowAtIndexPAth方法如下:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: FlightsDetailCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as FlightsDetailCell
cell.userInteractionEnabled = false
if indexPath.section == 0 {
cell.graphView.enableBezierCurve = true
cell.graphView.enableReferenceYAxisLines = true
cell.graphView.enableYAxisLabel = true
cell.graphView.colorYaxisLabel = UIColor.whiteColor()
cell.graphView.delegate = UIApplication.sharedApplication().delegate as BEMSimpleLineGraphDelegate
cell.graphView.dataSource = UIApplication.sharedApplication().delegate as BEMSimpleLineGraphDataSource
return cell
}
if indexPath.section == 1 {
cell.graphView.enableBezierCurve = true
cell.graphView.enableReferenceYAxisLines = true
cell.graphView.enableYAxisLabel = true
cell.graphView.colorYaxisLabel = UIColor.whiteColor()
cell.graphView.delegate = self
cell.graphView.dataSource = self
return cell
}
if indexPath.section …Run Code Online (Sandbox Code Playgroud) 我正在开发一个具有UITableViewController的应用程序,该应用程序显示值列表,如下所示:

如何将桌子向下移动,使其不与我的状态栏冲突?似乎我不能对这个场景施加任何约束,所以我不知所措.
有没有办法确定iOS设备的信号强度?
我发现了这个:iOS在Swift中获得信号强度(核心电话)
但这里似乎没有解决方案.是否为此编写了API?
请记住,我需要解决方案在应用商店中有效销售,因此它不能使用任何私有库.
下午好,
我最近组装了一个基于ATMega328P的微控制器PCB,这是我自己设计的.我对电路本身感觉很好,因为我设法通过Sparkfun AVR Pocket Programmer 上传Arduino Blink草图.
上传此草图后,我注意到ATMega正在使用其内部振荡器.我尝试通过Arduino IDE再次安装Arduino引导加载程序时,我感觉不舒服.
此时抛出了许多错误,但是电路板开始使用它的外部时钟并正确运行Blink程序.
我不能再向芯片上传任何代码,因为我无法让AVRDude在我的Mac上运行,我在Windows 8.1 PC上安装了AVRDude 5.1.
然后我连接了设备并发送:
avrdude -c usbtiny -p atmega328p
Run Code Online (Sandbox Code Playgroud)
这简单地返回:
avrdude: Error: Could not find USBtiny device ( 0x1781/0xc9f)
Run Code Online (Sandbox Code Playgroud)
我是否无意中歪斜了芯片的熔丝位?我怎么能保存这个芯片?
更新:我设法安装AVRDude 6.0.1现在错误如下:
avrdude: initialization failed, rc=-1
Run Code Online (Sandbox Code Playgroud)
完整结果如下:

我有一个UITableViewController,当前显示4个单元格,将始终显示,并希望将它们组合在一起,但我无法弄清楚如何.我发现的资源仅在通过UIViewController或其他类似的东西插入标准UITableView时使用Interface Builder提供指令.如何以编程方式对它们进行分组?
这是我当前的UITableViewController类:
import UIKit
class SecondViewController: UITableViewController {
let Items = ["Altitude","Distance","Groundspeed"]
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.Items.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel?.text = self.Items[indexPath.row]
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序中目前有两个NSTimer计时器,它们负责获取数据和更新UI。最近我注意到,当计时器运行时,我的UI性能很差,例如,用户无法很好地滚动UITableview或根本无法滚动。我在其他地方读过,可以将计时器推入不同的运行循环中,这可能会有所帮助。这是我的计时器现在的样子:
let aSelector : Selector = "updateLocation"
timer = NSTimer.scheduledTimerWithTimeInterval(((NSUserDefaults.standardUserDefaults().stringForKey("mapUpdate")! as NSString).doubleValue), target: self, selector: aSelector, userInfo: nil, repeats: true)
Run Code Online (Sandbox Code Playgroud)
如何修改Swift计时器,使其在后台线程中运行?我一直在阅读,但一直感到困惑。
我在iOS应用程序中使用Google Maps API.在会话结束时,地图缩小并捕获屏幕截图.不幸的是,在拍摄屏幕截图之前,地图通常没有时间加载缩放曝光的所有图块.
我看到Apple的MKMapView有一个mapViewDidFinishLoadingMap委托.Google API中是否提供了类似的内容?
swift ×9
ios ×5
uitableview ×3
arduino ×2
atmega ×1
avrdude ×1
google-maps ×1
if-statement ×1
iokit ×1
nstimer ×1
serial-port ×1
statusbar ×1
string ×1
xcode ×1