有没有办法在迅速否定"如果让"?这看起来很愚蠢:
if let type = json.type {
} else {
XCTFail("There is no type in the root element")
}
Run Code Online (Sandbox Code Playgroud)
我不能使用XCTAssertNotNil,因为json.type是一个枚举.
enum JSONDataTypes {
case Object
case Array
case Number
case String
}
Run Code Online (Sandbox Code Playgroud)
非常感谢
编辑:这是一个:
var type: JSONDataTypes? = nil
Run Code Online (Sandbox Code Playgroud) 有没有从我的Swift应用程序中设置系统主卷的解决方案?
我读了很多关于AudioToolbox的内容,并在Objective-C中阅读了一些源代码示例.例如,我发现这一点:在10.6之后以编程方式设置Mac OS X卷
但我无法让它在Swift中运行.
我在https://developer.apple.com/library/mac/documentation/AudioToolbox/Reference/AudioHardwareServicesReference/index.html#//apple_ref/c/func/AudioHardwareServiceGetPropertyData中遗漏了一些示例代码
我的iOS应用程序中有折线图视图.
@IBOutlet weak var lineChartView: LineChartView!
Run Code Online (Sandbox Code Playgroud)
启用缩放和触摸.我不让用户在图表中做任何事情,甚至不允许选择.
我试过了:
self.lineChartView.pinchZoomEnabled = false
self.lineChartView.dragEnabled = false
self.lineChartView.dragDecelerationEnabled = false
Run Code Online (Sandbox Code Playgroud)
但没有任何运气.我仍然可以触摸图表并看到十字架.我甚至可以捏缩放图形.
如何关闭此行为?+
我正在尝试在 Linux 上构建一个使用 Foundation 的命令行工具。但我遇到了一个错误,因为我找不到解决方案:
swiftc -static-stdlib Sources/main.swift Sources/array.swift Sources/check.swift
/usr/bin/ld.gold: error: cannot find -lFoundation
/tmp/main-3a78a1.o:/tmp/main-3a78a1.o:function main: error: undefined reference to '_TMV10Foundation12CharacterSet'
/tmp/main-3a78a1.o:/tmp/main-3a78a1.o:function main: error: undefined reference to '_TWPV10Foundation12CharacterSets10SetAlgebraS_'
/tmp/main-3a78a1.o:/tmp/main-3a78a1.o:function main: error: undefined reference to '_TFE10FoundationSS10componentsfT11separatedByVS_12CharacterSet_GSaSS_'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
有人知道如何静态构建 swift 项目吗?
我想快速列出所有可用的音频设备,以提供输入和输出的选择。我的应用程序应该收听一个音频通道并“写入”另一个。我不要系统默认!
let devices = AVCaptureDevice.devices(for: .audio)
print(devices.count)
for device in devices {
print(device.localizedName)
}
Run Code Online (Sandbox Code Playgroud)
该代码列出了 0 个设备。但我希望至少有内部输出。
一些解释音频源选择的 CoreAudio、AudioToolbox 和 AVFoundation 的链接会很好。
我设法在Apples CloudKit中保存,更改和删除记录.我甚至收到订阅的通知,我不知道的是,我如何列出当前用户的所有订阅.
到目前为止,这是我的代码:
let operation = CKFetchSubscriptionsOperation()
operation.fetchSubscriptionCompletionBlock = { (d, e) -> Void in
println("got subscription")
if e != nil {
println("Error")
dump(e)
}
dump(d)
}
publicDatabase.addOperation(operation)
Run Code Online (Sandbox Code Playgroud)
我得到的是:
got subscription
Error
- <CKError 0x14db0ed0: "Invalid Arguments" (12)> #0
- 0 key/value pairs
Run Code Online (Sandbox Code Playgroud)
什么是无效参数?我如何获得所有已保存订阅的列表?
有没有办法在swift代码中获取产品版本号,比如
println("Running version \($PRODUCT_VERSION)")
Run Code Online (Sandbox Code Playgroud)
我必须定义一些standartUserDefaults,它们绑定到Version和build number,我不喜欢在构建时将它们放入我的代码中.
NSProcessInfo没有内部版本号.对我有什么建议吗?
swift ×6
macos ×3
cocoa ×2
ios ×2
xcode ×2
audio ×1
audiotoolbox ×1
build ×1
cloudkit ×1
foundation ×1
ios-charts ×1
linux ×1
subscription ×1