When creating a new SwiftUI project (either Xcode 12 or 12.2) and selecting both CoreData and CloudKit options, running the app on an iOS device shows absolutely nothing.
This is not the case if creating a universal project and running it on macOS, which works and shows some UI.
It's just a blank screen on iOS.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Is there a setting am I missing or Simulator is just broken on Beta 2 and won't go on the Internet?
Xcode 12.4 is working fine. Other devs see this as well.
Nothing in the release notes.
Any workaround?
I have a list of navigation links that I want to be draggable. However, it seems like onDrag conflicts with mouse clicks on macOS (iOS is fine).
Here's some sample code:
swift
import SwiftUI
struct ContentView: View {
var items = ["Peter", "Mark", "Joe", "Frank", "Tim"]
@State var selected: String?
var body: some View {
NavigationView {
List {
ForEach(items, id: \.self) { item in
NavigationLink(destination: Text(item), tag: item, selection: $selected, label: {
Text(item)
.onDrag { () - NSItemProvider in
return NSItemProvider(object: String(item) as NSString)
}
})
}
}
Text("")
}
}
}
Here's the weird part: if you click on the text, the item doesn't get selected and the link seems disabled. However, if you click on a section of the item that is empty, then it works!
Again, this works just fine on iOS. Is this a SwiftUI bug/limitation or am I doing it wrong?
Thanks!
This code works fine on macOS 11:
var body: some View {
VStack {
ActionControl()
.padding()
.onDrag { () -> NSItemProvider in
let value = Action(string: "hello, world").string
let p = ActionProfile(value: value)
return NSItemProvider(item: p, typeIdentifier: ActionProfile.pasteboardType)
}
MyTextView()
.padding()
}
}
class ActionProfile: NSObject, NSCoding, NSSecureCoding {
static var supportsSecureCoding: Bool = true
static var pasteboardType = "com.my.app.action.profile"
@objc var rawValue: String
func encode(with aCoder: NSCoder) {
aCoder.encode(rawValue, forKey: "value")
}
required init(value: String) {
self.rawValue = value
}
required init?(coder aDecoder: NSCoder) {
self.rawValue = aDecoder.decodeObject(of: NSString.self, forKey: "value")! as String
}
required init?(pasteboardPropertyList propertyList: Any, ofType type: NSPasteboard.PasteboardType) {
return nil
}
}
extension ActionProfile: NSPasteboardWriting, NSPasteboardReading {
static var nsPasteboardType: NSPasteboard.PasteboardType = .init(pasteboardType)
static func readingOptions(forType type: NSPasteboard.PasteboardType, pasteboard: NSPasteboard) -> NSPasteboard.ReadingOptions {
return .asKeyedArchive
}
func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType]
}
func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? {
if type == ActionProfile.nsPasteboardType {
return try! NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false)
}
return nil
}
static func readableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType]
}
}
extension MyTextViewControl {
override internal var writablePasteboardTypes: [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType] + super.writablePasteboardTypes
}
override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool {
return true
}
override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation {
let location = self.characterIndexForInsertion(at: self.convert(sender.draggingLocation, from: nil))
self.setSelectedRange(NSRange(location: location, length: 0))
return sender.draggingSource is MyTextViewControl ? .move : .copy
}
override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
let pboard = sender.draggingPasteboard
if pboard.availableType(from: [ActionProfile.nsPasteboardType]) == ActionProfile.nsPasteboardType {
if let profiles = pboard.readObjects(forClasses: [ActionProfile.self], options: nil) as? [ActionProfile], !profiles.isEmpty {
let alert = NSAlert()
alert.messageText = "WORKS"
alert.runModal()
return true
}
else {
let alert = NSAlert()
alert.messageText = "FAILED"
alert.runModal()
return super.performDragOperation(sender)
}
}
return super.performDragOperation(sender)
}
}
On macOS 12 beta, when calling pboard.readObjects(...) I get this error when trying to drag the item into a NSTextView:
Failed to initialize keyed unarchiver for pasteboard data: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?}
I've noticed that encode(with aCoder: NSCoder) isn't called at all on macOS 12 but is on macOS 11.
Are there any changes in macOS 12 regarding NSCoding or NSSecureCoding or is this just a bug?
Am I wrong or is it not possible to share Core Data+CloudKit with a keyboard extension?
It works if I set an app group but then I lose the CloudKit sync feature, which is not acceptable for me.
Is there some other way to share the data while keeping sync?
So I've started using TestFlight for Mac but unlike its iOS counterpart, it seems like every single build uploaded and pushed to testers has to be reviewed by Apple.
This is not how that works on the iOS side.
Ex:
MyApp 4.1 build 1 -> Review required for both iOS and Mac
MyApp 4.1 build 2 -> Review required for Mac, not iOS
Is this a bug or by design? If so, this is crazy!
Calling DNSServiceNATPortMappingCreate returns kDNSServiceErr_NoError like expected but the port mapping actually fails right away in the callback.
I'm calling this in a daemon via XPC. Are there new restrictions or permissions required?
Hi,My iOS Swift app contains a in-house built framework (A), which is also using Swift. This framework includes 2 in-house built frameworks (B and C) using Objective-C."Embedded Content Contains Swift Code" is set to YES for the app and to NO for the A, B and C frameworks.When I try to submit the app to iTC, I get these errors:ERROR ITMS-90205: "Invalid Bundle. The bundle at 'yourapp.app/Frameworks/A.framework' contains disallowed nested bundles."...ERROR ITMS-90206: "Invalid Bundle. The bundle at 'yourapp.app/Frameworks/A.framework' contains disallowed file 'Frameworks'."...How can I fix those?
Hi! What is wrong with this code and why does this work for a Picker but not a List?
struct ContentView: View {
enum FooBar: CaseIterable, Identifiable {
public var id : String { UUID().uuidString }
case foo
case bar
case buzz
case bizz
}
@State var selectedFooBar: FooBar = .bar
var body: some View {
VStack {
Picker("Select", selection: $selectedFooBar) {
ForEach(FooBar.allCases) { item in
Text(self.string(from: item)).tag(item)
}
}
List(FooBar.allCases, selection: $selectedFooBar) { item in
Text(self.string(from: item)).tag(item)
}
Text("You selected: \(self.string(from: selectedFooBar))")
}
}
private func string(from item: FooBar) -> String {
var str = ""
switch item {
case .foo:
str = "Foo"
case .bar:
str = "Bar"
case .buzz:
str = "Buzz"
case .bizz:
str = "Bizz"
}
return str
}
}
I'm able to retrieve the URL for iCloud Drive but what I want to do is store my app documents in the "On My iPad" / MyApp.
Using FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) just returns the document folder for the app container.
How can I access the public folder?
Thanks!
As of now, it seems impossible to set focus on a text field that is embedded in an alert on macOS.
struct ContentView: View {
@FocusState private var focusedField: FocusField?
@State private var showingAlert = false
@State private var name = ""
enum FocusField {
case folderName
}
var body: some View {
VStack {
Button {
// focusedField = .folderName // Not working either
showingAlert.toggle()
} label: {
Text("Show alert")
}
.alert("Alert", isPresented: $showingAlert, actions: {
TextField("Name", text: $name)
.font(.body)
.autocorrectionDisabled()
.focused($focusedField, equals: .folderName)
Button("Cancel", role: .cancel, action: {})
})
#if os(macOS)
.defaultFocus($focusedField, .folderName)
#endif
}
.padding()
}
}
When running this code on iOS, the text field does get focus automatically. Is it me that is doing something wrong or it's just a SwiftUI shortcoming on macOS?
Why won't a button using a Label show in the keyboard shortcuts list (holding ⌘ key)?
struct ContentView: View {
var body: some View {
NavigationSplitView {
SidebarView()
} detail: {
Text("Hello, world")
}
}
}
struct SidebarView: View {
let items = [1, 2, 3, 4, 5, 6]
var body: some View {
List(items, id:\.self) { item in
Text("\(item)")
}
.toolbar {
Button {
// Do something
} label: {
Label("New", systemImage: "plus")
}
.keyboardShortcut("n") // Will NOT show in shortcuts list
Button("Play") {
// Do something
}
.keyboardShortcut("p") // Will show in shortcuts list
}
}
}
Am I doing something wrong or is this just yet another SwiftUI shortcoming?
It seems like there's no way to set a placeholder in a text field when it is in a form on macOS. This is not an issue on iOS.
import SwiftUI
struct ContentView: View {
@State private var textUp = ""
@State private var textDown = ""
var body: some View {
VStack {
Form {
Text("In a form:")
.fontWeight(.bold)
TextField("placeholder", text: $textUp)
}
Text("Not in a form:")
.fontWeight(.bold)
TextField("placeholder", text: $textDown)
}
.padding()
}
}
Am I missing something or is this just not supported?
I'm trying to display a Label in a TableColumn but the header is not rendered properly:
Here's some code:
struct Computer: Identifiable {
let id: UUID
let name: String
init(_ name: String) {
id = UUID()
self.name = name
}
}
struct ContentView: View {
private var computers = [Computer("iMac"), Computer("MacBook"), Computer("Mac mini")]
@State private var selectedComputers = Set<Computer.ID>()
@State private var sortOrder = [KeyPathComparator(\Computer.name)]
var body: some View {
Table(computers, selection: $selectedComputers, sortOrder: $sortOrder) {
// Header rendered incorrectly
TableColumn("Name", value: \.name) { computer in
Label(computer.name, systemImage: "desktopcomputer")
}
// This works:
// TableColumn("Name", value: \.name)
}
}
}
If I use a Text element instead (or not define any custom view for the TableColumn), the header is rendered properly:
Am I doing it wrong or this is a bug?
I don't know if this is a bug but when you put text fiels in a form, pressing the Tab key on a physical keyboard will just jump to the first field and stay there:
import SwiftUI
struct ContentView: View {
enum FocusedField {
case firstName, lastName
}
@State var name = ""
@State var lastName = ""
@FocusState private var focusedField: FocusedField?
var body: some View {
Form {
TextField("Name", text: $name)
.focused($focusedField, equals: .firstName)
TextField("Last", text: $lastName)
.focused($focusedField, equals: .lastName)
}
.padding()
.onAppear {
focusedField = .firstName
}
}
}
This is the result:
Note that this works fine on macOS or when using the Tab key on the virtual keyboard.
If you put the fields into a VStack instead, you'll be able to move through the fields via the Tab key.