在朱利安日计算器上编写一些单元测试时,我发现1847年12月2日之前的日期被NSDate错误地初始化.他们似乎有75秒加入.我找不到任何指向那个日期的东西(这是在格里高利历年截止之后).这是一个错误还是我没有遇到历史性的日历调整?
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *dateComps = [NSDateComponents new];
dateComps.year = 1847;
dateComps.month = 12;
dateComps.day = 1;
NSDate *d1 = [cal dateFromComponents:dateComps];
NSLog(@"d1 = %@", d1);
dateComps = [NSDateComponents new];
dateComps.year = 1847;
dateComps.month = 12;
dateComps.day = 2;
NSDate *d2 = [cal dateFromComponents:dateComps];
NSLog(@"d2 = %@", d2);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
d1 = 1847-12-01 00:01:15 +0000
d2 = 1847-12-02 00:00:00 +0000
版本8.0 beta 5.
我最近安装了上面的Xcode测试版,但是我无法运行任何iOS 10.0模拟器.我已经在8 beta和Xcode 7上进行了各种卸载,清除了目录并重新启动但没有成功.重新安装后,我仍然无法运行iOS 10.0模拟器.(我已经将Xcode下载复制到另一台机器并成功解压缩并安装在那里没有任何问题,所以它不是一个损坏的下载.)
xcrun产生以下信息... 09:44:13~> xcrun simctl list
== Device Types ==
iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)
:
iPad Pro (9.7-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--9-7-inch-)
iPad Pro (12.9-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro)
Apple TV 1080p (com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p)
== Runtimes ==
iOS 8.1 (8.1 - 12B411) (com.apple.CoreSimulator.SimRuntime.iOS-8-1)
iOS 9.3 (9.3 - 13E233) (com.apple.CoreSimulator.SimRuntime.iOS-9-3)
iOS 10.0 (10.0 - 14A5335a) (com.apple.CoreSimulator.SimRuntime.iOS-10-0) (unavailable, failed to open liblaunch_sim.dylib)
tvOS 10.0 (10.0 - 14T5321a) (com.apple.CoreSimulator.SimRuntime.tvOS-10-0)
== Devices ==
-- iOS 8.1 --
-- iOS …
我在类中有以下功能:
/// Returns the weather conditions at the given location.
/// - parameter for: A location on the Earth's surface.
/// - returns: If found, the `WeatherConditions` at the supplied location otherwise nil.
public func conditions(for location: Location) -> WeatherConditions? {
return nil // The actual code is not important to the question.
}
Run Code Online (Sandbox Code Playgroud)
这被称为如下let myWeather = conditions(for: myLocation).
代码工作正常,问题是关于文档.下图是该conditions功能的"快速帮助"窗口中显示的内容.假定函数的用户必须使用外部参数label(for),并且我已经明确记录了该标签,那么快速帮助窗口中的参数行是否应该读取Parameters for而不是Parameters location?
这是Xcode中的错误还是显示(内部)参数名称而不是外部参数标签的原因?
我正在组装一个类,它有一个由枚举定义的状态,以及一个只读属性"state",它返回实例的当前状态.我希望使用KVO技术来观察状态的变化,但这似乎不可能:
dynamic var state:ItemState // Generates compile-time error: Property cannot be marked dynamic because its type cannot be represented in Objective-C
我想我可以将每个状态表示为Int或String等,但是有一个简单的替代解决方法可以保留enum否则会提供的类型安全性吗?
文斯.
Xcode 11.3 (11C29).
macOS 10.15.2.
Run Code Online (Sandbox Code Playgroud)
下面的 SwiftUI 视图中有两个按钮。一个打印“确定”,另一个打印“取消”。但是,无论按下哪个按钮,都会执行两个打印语句。 这是为什么?(我认为这一定是 SwiftUI 的 bug。)
struct ContentView: View {
var body: some View {
List {
HStack {
Button("OK") {
print("OK.")
}
Button("Cancel") {
print("Cancel")
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
(如果 theList或 theHStack被注释掉,则每个按钮仅打印其自己的语句。)
我正在寻找 pyc 文件格式规范。我发现这个链接提供了没有操作码的字节码指令,但我需要更多详细的文件,其中包括.pyc. 谁能给我一个链接?
(macOS 10.15 beta和Xcode 11 beta 5)
我正在研究的SwiftUI教程(https://www.raywenderlich.com/3715234-swiftui-getting-started#toc-anchor-005)包含以下视图:
struct ColorSliderView: View {
@Binding var value: Double
let textColor: Color
var body: some View {
HStack {
Text("0").foregroundColor(textColor)
Slider(value: $value, in: 0.0...1.0)
Text("255").foregroundColor(textColor)
}.padding()
}
}
Run Code Online (Sandbox Code Playgroud)
该视图与另一个视图在同一文件中声明,并且可以作为该视图的组件进行预览。
正如本教程中使用的那样,它可以工作,但是后来我将视图提取到了自己的文件中,并添加了以下预览:
#if DEBUG
struct ColorSliderView_Previews: PreviewProvider {
static var previews: some View {
return ColorSliderView(value: 0.5, textColor: .red)
}
}
#endif
Run Code Online (Sandbox Code Playgroud)
这将引发错误“ 无法将类型为'Double'的值转换为预期的参数类型'Binding << Double >>' ”。
问题:如何在预览中声明值为0.5的Binding << Double >>?
(另外:如何在问题中正确包含尖括号(不加倍)?
今天,我看到了一些示例Swift 2.0(Xcode 7.2)代码,可以概括为:
let colours = ["red", "green", "blue"]
let r1 = colours.contains("The red one.".containsString) // true
let y1 = colours.contains("The yellow one.".containsString) // false
Run Code Online (Sandbox Code Playgroud)
由于containsString()函数缺少括号,我原本期望编译错误.事实上,我甚至不确定递归是如何工作的.字符串是否在colours数组中的每个项目中递归,反之亦然?
任何解释都赞赏.
下面的代码来自一个简单的 SwiftUI ContentView。它显示一段文本和一张图像,我希望它们沿其中心线垂直对齐。
var body: some View {
HStack(alignment: .center) {
Text("Cloudy")
.background(Color.yellow)
Image(systemName: "cloud.heavyrain")
.background(Color.blue)
}
.font(.largeTitle)
.border(Color.red)
}
Run Code Online (Sandbox Code Playgroud)
相反,我发现它们似乎以框架为中心。对于文本来说,框架太大,对于图像来说,框架太小。
是否可以对齐内容(特别是图像 - 似乎没有边界)而不是框架?
Xcode 7.2,Swift 2.0:下面的代码在调试区域中打印"15()".我原以为它打印"15 1".为什么要打印括号?
var n = 15
print(n, n /= 10)
Run Code Online (Sandbox Code Playgroud)