我遇到了与内存相关的问题,也就是说,每当我转到另一个视图然后回退(关闭)时,内存就会不断堆积。
我的第二个viewController中有以下代码。但是,它不会取消分配内存。
override func viewWillDisappear() {
super.viewWillDisappear()
self.dismissController(self)
self.removeFromParentViewController()
}
Run Code Online (Sandbox Code Playgroud)
提前致谢。
我目前正在使用 CoreBluetooth 开发 BLE 设备。我可以通过找到我的设备CBCentralManagerDelegate并连接到我的设备。
当我想发现一个服务的特性时,我可以得到正确的uuid,但是特性的值是nil。有任何想法吗?
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
if error != nil {
print("ERROR DISCOVERING CHARACTERISTICS: \(error?.localizedDescription)")
return
}
if let characteristics = service.characteristics {
for characteristic in characteristics {
print("--------------------------------------------")
print("Characteristic UUID: \(characteristic.uuid)")
print("Characteristic isNotifying: \(characteristic.isNotifying)")
print("Characteristic properties: \(characteristic.properties)")
print("Characteristic descriptors: \(characteristic.descriptors)")
print("Characteristic value: \(characteristic.value)")
}
}
}
-------------------------------------------------------------------
Characteristic UUID: FA01
Characteristic isNotifying: false
Characteristic properties: CBCharacteristicProperties(rawValue: 26)
Characteristic descriptors: nil
Characteristic value: nil
Run Code Online (Sandbox Code Playgroud)
根据蓝牙 …
我想要只获得子目录.这是我的数据结构.
根/
我想获取特定文件夹(root)中的目录.我在根文件路径中使用枚举器:
let enumerator = NSFileManager.defaultManager().enumeratorAtPath(filePath)
for element in enumerator! {
print(element)
}
Run Code Online (Sandbox Code Playgroud)
但是,它将迭代root中的每个文件.我怎样才能获得子目录(a&b)?
在我的应用程序中,我想访问带有安全范围书签的本地文件目录.
如App Sandbox设计指南中所述,我将用户指定的文件夹(NSOpenPanel)存储在安全范围的书签中(作为NSData).
但是,我发现Swift中不再提供URLByResolvingBookmarkData.我不知道如何在重新启动应用程序后访问该URL并将权限授予我之前选择的目录.有任何想法吗?
/// OpenPanel and set the folderPath
var folderPath: NSURL? {
didSet {
do {
let bookmark = try folderPath?.bookmarkDataWithOptions(.SecurityScopeAllowOnlyReadAccess, includingResourceValuesForKeys: nil, relativeToURL: nil)
} catch {
print("Set bookMark fails")
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图用自己的图像构建一个框架,它编译得很好。但是,当我在另一个项目中包含我的框架时,它在加载图像时崩溃,知道吗?
ImageTest(我的框架)
public class ImageTest {
open func getImage() {
return #imageLiteral(resourceName: "IMG_0745")
}
}
Run Code Online (Sandbox Code Playgroud)
我的项目
import ImageTest
...
...
override func viewDidLoad() {
super.viewDidLoad()
let imageView = UIImageView(image: ImageTest.getImage()) // crash !
imageView.center = view.center
view.addSubview(imageView)
}
Run Code Online (Sandbox Code Playgroud)
苹果今年在 iOS11 上引入了Core ML。有一个Core ML 工具可以将训练好的模型转换为 Core ML 格式 (.mlmodel)。
是否可以使用 Tensorflow 转换 Core ML 模型?如何?
我想检测我的应用程序中插入/删除的特定USB.现在,我可以通过本教程使用USB设备接口获取deviceName .但是,如何在Swift 中执行(deviceAdded)IOServiceMatchingCallBack的回调函数.
我尝试如下,但我收到一个错误:无法将类型'(UnsafePointer,iterator:io_iterator_t) - >()'的值转换为预期的参数类型'IOServiceMatchingCallback!'
func detectUSBEvent() {
var portIterator: io_iterator_t = 0
var kr: kern_return_t = KERN_FAILURE
let matchingDict = IOServiceMatching(kIOUSBDeviceClassName)
let vendorIDString = kUSBVendorID as CFStringRef!
let productIDString = kUSBProductID as CFStringRef!
CFDictionarySetValue(matchingDict, unsafeAddressOf(vendorIDString), unsafeAddressOf(VendorID))
CFDictionarySetValue(matchingDict, unsafeAddressOf(productIDString), unsafeAddressOf(ProductID))
// To set up asynchronous notifications, create a notification port and add its run loop event source to the program’s run loop
let gNotifyPort: IONotificationPortRef = IONotificationPortCreate(kIOMasterPortDefault)
let runLoopSource: Unmanaged<CFRunLoopSource>! = IONotificationPortGetRunLoopSource(gNotifyPort)
let gRunLoop: …Run Code Online (Sandbox Code Playgroud)