环境: Xcode Version 12.3 (12C33)
Version 12.3 (12C33)
我注意到NavigationTitle在更新到 Xcode 12.3 RC 后会破坏自动布局。
这是一个简单的示例(根据注释修改为现代语法):
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
VStack(alignment: .center, spacing: 10) {
Text("Hello, world!")
.padding()
}.navigationTitle(Text("Greetings World!"))
.navigationBarTitleDisplayMode(.inline)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在运行时得到的:
2020-12-09 11:42:19.994389-0800 UICheck[26092:799713] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you …Run Code Online (Sandbox Code Playgroud) 如何切换是否隐藏按钮的存在?
我们有无条件的 .hidden() 属性;但我需要有条件的版本。
注意:我们确实有.disabled(bool)属性可用,但没有.hidden(bool)。
struct ContentView: View {
var body: some View {
ZStack {
Color("SkyBlue")
VStack {
Button("Detect") {
self.imageDetectionVM.detect(self.selectedImage)
}
.padding()
.background(Color.orange)
.foreggroundColor(Color.white)
.cornerRadius(10)
.hidden() // ...I want this to be toggled.
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我注意到从iOS 8.0开始,所有NSCalendarUnits(例如NSDayCalendarUnit)都被正式弃用.
什么是替代品?
struct Item {
var name:String?
var type:String?
var value:Int?
var tag:Int?
}
...
...
let petItem = Item(name:petName!.uppercaseString, type:petType, value:0, tag:0)
self.statusLabel.hidden = false
if addItem(petItem) {
self.statusLabel.text = petName! + " successfully added."
self.textField.becomeFirstResponder()
} else {
self.statusLabel.text = "Sorry, Pet couldn't be added."
}
...
...
func addItem(petItem:Item) -> Bool {
if treeIsFull() {
println("Tree is full\n")
} else {
petItem.name = "turkey" <--- *** error ***
...
Run Code Online (Sandbox Code Playgroud)
我无法为结构的任何成员赋值.
我收到以下错误:
错误:无法将'name'分配给'petItem'.
是否有补救措施或者我必须在实例创建期间分配所有值?
我收到Xcode6-Beta 4后发现没有文档.我对iOS 8文档特别感兴趣.
如何获得Xcode和Dash的iOS 8文档?
访问成员struct变量的正确语法是什么?我目前正在尝试这样:
struct one {
var name:String = "Ric"
var address:String = "Lee"
}
one.name
Run Code Online (Sandbox Code Playgroud)
但最后一行产生错误:
'one.Type'没有名为'name'的成员
如何在我的struct上访问变量?
场景:
我希望减少iTouch照片库中单个视频的大小.
1.从库中收集视频资产.
2.获取PHAsset的缩略图 - 有效.
3.从库中获取实际视频.
4.从库中请求AVAssetForVideo.
5.通过ExportSessions转换视频...加载各种参数.
6.尝试将导出运行到tmp目录以供使用.
*失败*
这是调试输出:
这是错误消息:

func getVideoFromPhotoLibrary() {
let videoAssets = PHAsset.fetchAssetsWithMediaType(.Video, options:nil)
videoAssets.enumerateObjectsUsingBlock {
(obj:AnyObject!, index:Int, stop:UnsafeMutablePointer<ObjCBool>) in
let mySize = CGSizeMake(120,120)
let myAsset = obj as! PHAsset
let imageManager = PHImageManager.defaultManager()
var myVideo:BlissMedium?
// Request the poster frame or the image of the video
imageManager.requestImageForAsset(myAsset, targetSize:mySize, contentMode: .AspectFit, options: nil) {
(imageResult, info) in
let thumbnail = UIImage(named:"videoRed")
myVideo = BlissMedium(blissImage: imageResult, creationDate:myAsset.creationDate)
myVideo!.mediumType = .video
}
// Actual Video: …Run Code Online (Sandbox Code Playgroud) 将.txt文件组件附加到URL路径不起作用:
var error:NSError?
let manager = NSFileManager.defaultManager()
let docURL = manager.URLForDirectory(.DocumentDirectory, inDomain:.UserDomainMask, appropriateForURL:nil, create:true, error:&error)
docURL.URLByAppendingPathComponent("/RicFile.txt") <-- doesn't work
Run Code Online (Sandbox Code Playgroud)
通过调试器:
file:///Users/Ric/Library/Developer/CoreSimulator/Devices/
<device id>/data/Containers/Data/Application/<app id>/Documents/
Run Code Online (Sandbox Code Playgroud)
使用docURL将字符串写入文件不起作用,因为缺少文件名.
原因(通过错误):
"操作无法完成.是一个目录"
所以问题:为什么以下不起作用?
docURL.URLByAppendingPathComponent("/RicFile.txt")
Run Code Online (Sandbox Code Playgroud) 我正在玩弄 SwiftUI 中的图像显示,并决定附加警报以在找不到图像时激活。
以下是缩略代码:
struct ContentView: View {
...
@State var image: URLImage = URLImage()
...
@State var showActionSheet = true
var body: some View {
ZStack {
Color.green
NavigationView {
VStack {
Button(action: {
self.url = "https://xxxx.org/\(Int.random(in: 0 ..< 10)).png"
self.image.imageLoader.load(url: URL(string: self.url)!)
}) {
Text("Get Random Image")
}
image.actionSheet(isPresented: $showActionSheet) {
ActionSheet(title: Text("Action Time"), message: Text("Greetings Ric!"), buttons:
[.default(Text("First Button"), action: {
print("First Button")
})])
}
}.navigationBarTitle(Text("Ric's Images"))
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我将“showAlertSheet”标志设置为“true”时,我会收到警报,但也会收到编译器的约束投诉:
2019-11-25 12:41:21.628064-0800 GetImages[32413:1078621] …
swift ×4
swiftui ×3
ios ×2
struct ×2
avfoundation ×1
button ×1
delegates ×1
ios8 ×1
nscalendar ×1
nsurl ×1
objective-c ×1
video ×1
writetofile ×1
xcode6 ×1