I am trying to create demo for spatial meeting using persona also refer apple videos, But not getting clear idea about it.
Any one could you please guide me step by step process or any code are appreciated for learning.
Swift
RSS for tagSwift is a powerful and intuitive programming language for Apple platforms and beyond.
Posts under Swift tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
This code works when I run it in the iOS Simulator with iOS 17.0.1:
let passcodeInput = springboard.secureTextFields["Passcode field"]
_ = passcodeInput.waitForExistence(timeout: 10)
passcodeInput.tap()
However if I run it on the iOS Simulator with iOS 17.4 I get this error:
t = nans Checking existence of `"Passcode field" SecureTextField`
t = nans Capturing debug information
t = nans Requesting snapshot of accessibility hierarchy for app with pid 66943
t = nans Tap "Passcode field" SecureTextField
t = nans Wait for com.apple.springboard to idle
t = nans Find the "Passcode field" SecureTextField
t = nans Find the "Passcode field" SecureTextField (retry 1)
t = nans Find the "Passcode field" SecureTextField (retry 2)
t = nans Requesting snapshot of accessibility hierarchy for app with pid 66943
<unknown>:0: error: PRCheckUITests : Failed to tap "Passcode field" SecureTextField: No matches found for Descendants matching type SecureTextField from input {(
Application, pid: 66943, label: ' '
)}
Did the hardcoded string "Passcode field" change for iOS 17.4?
How can I access the passcode field through springboard in a test?
There seems to be a problem with placing multiple NavigationLinks on a List item row in SwiftUI. If I have two links on the same row and tap one of them, SwiftUI seems to create a path using both links. Irrespective of which of the two is tapped, the view specified by the first (left-hand) appears. Tapping Back reveals the view specified by the second (right-hand) link. Tapping again returns to the list.
This problem has been mentioned before in relation to Buttons. The solution offered was to use button styles, and make sure the button areas do not overlap (how could they overlap?). This does not work
ChatGPT gave me a clear example, which it claimed would work, but just demonstrates the problem
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List {
ForEach(0..<10) { index in
HStack {
NavigationLink(destination: DestinationView1(item: index)) {
Text("Navigate to View 1")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
.buttonStyle(PlainButtonStyle()) // Ensure the link only activates on its area
Spacer()
NavigationLink(destination: DestinationView2(item: index)) {
Text("Navigate to View 2")
.padding()
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(8)
}
.buttonStyle(PlainButtonStyle()) // Ensure the link only activates on its area
}
.padding(.vertical, 5)
}
}
.navigationBarTitle("Navigation Links")
}
}
}
struct DestinationView1: View {
var item: Int
var body: some View {
Text("Destination View 1 for item \(item)")
.navigationBarTitle("View 1", displayMode: .inline)
}
}
struct DestinationView2: View {
var item: Int
var body: some View {
Text("Destination View 2 for item \(item)")
.navigationBarTitle("View 2", displayMode: .inline)
Have a bug I'm trying to resolve on an app review through the store.
The basic flow is this:
User presses a button and enters a fully immersive space
While in the the fully immersive space, user presses the digital crown button to exit fully immersive mode and return to shared space (Note: this is not rotating the digital crown to control immersion level)
At this point I need an event or onchange (or similar) to know when a user is in immersive mode so I can reset a flag I've been manually setting to track whether or not the user is currently viewing an immersive space.
I have an onchange watching the scenePhase changes and printing to console the old/new values however this is never triggered.
Seems like it might be an edge case but curious if there's another way to detect whether or not a user is in an immersive scene.
I have set up a "Picker" which works well, EXCEPT that the Label won't appear, I have struggled around this and I am sure the solution is very simple, here's what I have.
import SwiftUI
import SwiftData
struct iPadReadingsEntry: View {
@State private var whatOccasion: String = ""
let occassions = ["Misc", "Breakfast", "Mid Day Meal", "Evening Meal", "Bed Time"]
var body: some View {
.
.
.
HStack{
Picker("Before What Occasion :", selection: $whatOccasion ){
ForEach(occassions, id: \.self) {
Text($0)
}
}.pickerStyle(MenuPickerStyle())
.background(Color(red: 255, green: 253, blue: 208))
Spacer()
}.padding(.leading, 80)
.padding(.bottom, 30)
.
.
.
DatePicker always get timeFormat from device setting, but i need to show time in datePicker based on My app setting not device setting. any solution for this problem
I tried to set locale "us_POSIX" locale for 12 hour and "us_GB" for 24 hour format this way is work in gregorian calendar , but in japanese calendar not showing year properly like (picker showing " 6 " instead of " Reiwa 6 " )
After updating to Mac OS Sonoma, we have encountered compatibility issues with our iPad-designed application, specifically with the AirPrint functionality, when it is run on MacOS. The AirPrint feature stopped working properly through UIPrintInteractionController.shared.
We have noticed that when we compile the application using Catalyst, the AirPrint functionality is restored and works as expected. However, this solution is not viable for us due to the restrictions associated with the frameworks we are utilizing.
We are seeking alternative solutions, and any help or guidance would be highly appreciated to resolve this issue and ensure a seamless and uninterrupted user experience in our application.
STEPS TO REPRODUCE
Create an app for ipad with just a button and this code
var str = "TEST"
let printInfo = UIPrintInfo(dictionary:nil)
printInfo.outputType = .general
printInfo.jobName = "Report"
printInfo.orientation = .portrait
let printController = UIPrintInteractionController.shared
printController.printInfo = printInfo
printController.showsNumberOfCopies = false
printController.showsPageRange = false
printController.showsNumberOfCopies = false
let formatter = UIMarkupTextPrintFormatter(markupText: str)
formatter.contentInsets = UIEdgeInsets(top: 72, left: 72, bottom: 72, right: 72)
printController.printFormatter = formatter
printController.present(animated: true, completionHandler: nil)
2.Run it on a MacOS with Sonoma, there is no error on console or anything but it don't work.
-If you run it with Catalyst it just works when adding the Printing permission of App Sandbox in Signing & Capabilities.
In swift if using custom dateFormat like "dd-mm-yyyy" and device follows japanese calendar now get dateForm dateFormatter , expected "30-05-Reiwa6". but dateFormatter return string is "30=05-0006"
I'm studying Swift programing with using Apple official document "Develop in Swift Tutorial" https://developer.apple.com/tutorials/develop-in-swift/.
When I do that, I faced to some problems which I cannot resolve myself.
So, could you help or advise me about it.
Problem:I can't implement this program which this below text say. How do I write the code??
(This section is that "Wrap-up: Lists and Text fields, Develop in Swift Tutorials")
Here's my current states...
import SwiftUI
struct ContentView: View {
@State private var names: [String] = []
@State private var nameToAdd = ""
@State private var pickedName = ""
@State private var shouldRemovePickedName = false
var body: some View {
VStack {
VStack(spacing: 8) {
Image(systemName: "person.3.sequence.fill")
.foregroundStyle(.tint)
.symbolRenderingMode(.hierarchical)
Text("Pick-a-Pal")
}
.font(.title)
.bold()
//3項条件演算子
Text(pickedName.isEmpty ? "" : pickedName)
.font(.title2)
.bold()
.foregroundStyle(.tint)
List {
ForEach(names, id: \.self) { name in
Text(name)
}
}
.clipShape(RoundedRectangle(cornerRadius: 8))
TextField("Add Name", text: $nameToAdd)
//単語の自動修正をオフにする
.autocorrectionDisabled()
.onSubmit {
if !nameToAdd.isEmpty {
names.append(nameToAdd)
nameToAdd = ""
}
}
Divider()
Toggle("Remove when picked", isOn: $shouldRemovePickedName)
Button {
if let randomName = names.randomElement() {
pickedName = randomName
if shouldRemovePickedName {
names.removeAll() { name in
return (name == randomName)
}
}
} else {
pickedName = ""
}
} label: {
Text("Pick Random Name")
.padding(.vertical, 8)
.padding(.horizontal, 16)
}
.buttonStyle(.borderedProminent)
.font(.title2)
}
.padding()
}
}
#Preview {
ContentView()
}
Hey there,
i implemented live activity in my app and iam trying to start the live activity from push notification, updates works fine even when the app is in background but starting the activity creating issue mostly on background and kill mode when i check the delivery of live activity on cloudkit console it says stored for device power considerations.
anyone having the same issue ?
I have obviously missed some subtle bit of code but I can't see what I am missing. I am getting a warning about my NavigationLink.
Result of 'NavigationLink<Label, Destination>' initializer is unused
Below I have included the code that has caused the warning and the code of the target of the Navigation link. The link does not work, though the button does, as proved by the print statement (see below). Here is the code that caused the warning:
import SwiftUI
import SwiftData
struct Main_Menu_iPad: View {
@Environment(\.modelContext) private var context
@Query private var readings: [Readings]
var body: some View {
ZStack {
Image("iPad Background 810 X 1060")
.resizable()
.scaledToFill()
.ignoresSafeArea()
VStack {
HStack{
Image("Diabetes Control Logo 1024X1024")
.resizable()
.frame(width: 100, height: 100, alignment: .leading)
.padding(.leading, 40)
Text("Diabetes Control")
.font(Font.custom("SnellRoundhand-Black", size: 40))
.background(Color(red: 255, green: 253, blue: 208))
.shadow(color: Color(red: 128, green: 128, blue: 128), radius: 3)
.padding(.leading, 150)
Spacer()
}.padding(.bottom, 35)
HStack {
Text("What would you like to do : ")
.font(Font.custom("SnellRoundhand-Black", size: 30))
.background(Color(red: 128, green: 128, blue: 128))
.shadow(color: Color(red: 126, green: 128, blue: 128), radius: 3)
Spacer()
}.padding(.leading, 35)
.padding(.bottom,35)
NavigationStack {
HStack {
Button {
print("I have been pressed")
NavigationLink {
iPadReadingsEntry()
} label: {
Text("Enter a BLOOD Glucose reading")
}
} label: {
Text("Enter a Blood Glucose Reading")
}.background(Color(red: 255, green: 253, blue: 208))
.foregroundColor(.black)
.font(Font.custom("SnellRoundhand", size: 24))
Spacer()
}.padding(.leading, 60)
.padding(.bottom, 25)
Spacer()
}.background(.blue)
Spacer()
}
}
}
}
#Preview {
Main_Menu_iPad()
}
And this is the code of the target view:
import SwiftUI
struct iPadReadingsEntry: View {
var body: some View {
ZStack {
Image("iPad Background 810 X 1060")
.resizable()
.scaledToFill()
.ignoresSafeArea()
VStack {
HStack{
Image("Diabetes Control Logo 1024X1024")
.resizable()
.frame(width: 100, height: 100, alignment: .leading)
.padding(.leading, 40)
Text("Diabetes Control")
.font(Font.custom("SnellRoundhand-Black", size: 40))
.background(Color(red: 255, green: 253, blue: 208))
.shadow(color: Color(red: 128, green: 128, blue: 128), radius: 3)
.padding(.leading, 150)
Spacer()
}.padding(.bottom, 35)
Spacer()
}
}
}
}
#Preview {
iPadReadingsEntry()
}
Finally is there a way of switching View without using a NavigationStack/NamigastinLink as it covers my background image?
My project is visionOS project. I add the package ‘swift-openapi-generator’ and add run build tool plug-ins as the vedio teached. When I build the project, xcode show me the error No such module 'Glibc'
We are using Material Textfield iOS component (as directed by our client), https://github.com/material-components/material-components-ios/blob/develop/components/TextControls/README.md , after ios 17.5.1 update, for all the material textfield on some iphone 14+ models there is a keyboard appearance issue, the keyboard starts to appear but dismisses immediately on tap of any textfeild,i.e material textfield component, apple's uitextfield works properly, we have an iphone 14+ with ios 17.5.1, for us it works without any issues, our app was uploaded using xcode 14.2, not sure how to fix this issue as we are not able to reproduce it, couple of users have reported this issue, it however works on all other iphone models!!! Any help would be greatly appreciated , i understand this is a third party SDK, but how to simulate this bug, if it is happening only on some devices and on the same device models we have, are working.
In my application, I query with @ModelActor. My goal in doing this is to perform the query operation in the background thread. I use .task(priority:) to display the queries. I want to use withAnimation inside the task, but as you know, it cannot be used with asynchronous functions. I'm waiting for your comments and ideas on how to do it. Thank you.
The context is to create a model instance in SwitfData and return it.
This model as a unique attribute (defined by @Attribute(.unique)). The application runs fine the first time but on the second run, it fails with EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP).
What the reason behind this crash?
Here is my sample application to duplicate the issue. The issue is reproducible on MacOS and iOS:
import SwiftUI
import SwiftData
@available(iOS 17, *)
@available(macOS 11, *)
@Model
public final class MyModel : CustomStringConvertible {
@Attribute(.unique) var uuid: UUID
init(uuid: UUID) throws {
self.uuid = uuid
}
public var description: String {
return self.uuid.uuidString
}
}
@available(iOS 17, *)
@available(macOS 11, *)
@ModelActor
public actor LocalDatabaseService {
public static let shared = LocalDatabaseService()
let schema = Schema([MyModel.self])
public init() {
self.modelContainer = try! ModelContainer(for: self.schema)
let context = ModelContext(modelContainer)
self.modelExecutor = DefaultSerialModelExecutor(modelContext: context)
}
public func createMyModel(uuid: UUID) throws -> MyModel {
let myModel = try MyModel(uuid: uuid)
let modelContext = self.modelContext
modelContext.insert(myModel)
try modelContext.save()
return myModel
}
}
struct ContentView: View {
var body: some View {
Task {
let id = UUID(uuidString: "9C66CA5B-D91C-480F-B02C-2D14EEB49902")!
let myModel = try await LocalDatabaseService.shared.createMyModel(uuid: id)
print("myModel:\(myModel)")
print("DONE")
}
return VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
}
}
#Preview {
return ContentView()
}
Note: a workaround is to returned the fetched model instance return try self.getMyModel(uuid: uuid):
func getMyModel(uuid: UUID) throws -> MyModel {
let fetchDescriptor = FetchDescriptor<MyModel>(predicate: #Predicate { $0.uuid == uuid })
let serverList = try modelContext.fetch(fetchDescriptor)
if !serverList.isEmpty {
if let first = serverList.first {
return first
}
}
fatalError("Could not find MyModel with uuid \(uuid)")
}
... but it does not explain the crash.
encountering so many bugs.
now getting trapped by the error
"Cannot find type R in scope"
for the typealias Localizable = R.string.localizable.
Is there any way for me to deploy my app?
as Apple stroe now only accept app built by Xcode 15.0 above
but Xcode 15.0 migration causing so many error.
I've been reading the documentation and apparently protocols force structures, classes or enumerations to implement specific methods or define certain variables.
I've double checked this functionality by typing the following code. In fact, xcode compiler helped me to verify this since it popped up an alert that depicted the following message : "Type MiguelStruc does not conform to protocol Miguels ..."
protocol Miguels {
func someF()-> Float
}
public struct MiguelStruc{
var miguelVar : String = "hey"
}
extension MiguelStruc: Miguels{
}
Now, while I was following the official swiftUI drawing paths and shapes tutorial I encountered this particular chain of code:
(https://developer.apple.com/tutorials/swiftui/drawing-paths-and-shapes)
Path { path in
}
.fill(.black)
By diving into the Swiftui documentation I noticed that Shape is a protocol
public protocol Shape : Sendable, Animatable, View
which is implemented by the Path structure
extension Path : Shape
Why none of the Path extensions content are explicitly implementing any of the Shape protocol requirements?
such as role, layoutDirectionBehavior, sizeThatFits, offset, intersection, union, and so on!
I'm new to SwiftUI and Xcode. I built and installed an app to test on my iPhone 15 Pro. On the Apple Development screen for my profile, I tapped Verify App and a dialog pops up with a Cancel and Verify button. It also tells me my internet connection will be used to do the verification. After tapping the Verify button "Apple Development" on the top of the screen quickly flashes one time and the app is still in the Not Verified state. No error message is ever displayed. It looks like I came across a bug in Apples verification process.
Please show me a detailed step by step work-around to this bug. I'm using Xcode 15.4
Thanks in advance.
We implemented passkeys Autofill feature in iOS 16.6. Later verified in iOS 17.0 as well. But when we upgraded to iOS 17.5, the available passkeys autofill prompt is disappeared now. No code changes were done from our side. Also upgraded to iOS 17.5.1 and checked, still doesn’t show the prompt on the keyboard.
For autofill we are calling 'performAutoFillAssistedRequests()' API on our ASAuthorizationController after fetching assertion options response from our Relying-Party. Our textFields content type is set to ‘username’.
Additional Info:
Before making the performAutoFillAssistedRequests() API call, when we click on the ‘Passwords’ icon on keyboard, it only shows the passwords saved on iPhone. But after making the call, we can see available passkeys as well in the list.
We are making the fetch assertion options response call on textField delegate after typing more than two characters.
I already raised a bug in Feedback Assistant on this - FB13809196. I attached a video and sysdiag file there.
Here is my current code:
@Model
final public class ServerModel {
@Attribute(.unique) var serverUrl: URL
init(serverUrl: URL) {
self.serverUrl = serverUrl
}
}
@ModelActor
public actor MyDatabaseService {
public static var shared = MyDatabaseService()
public init() {
self.modelContainer = try! ModelContainer(for: ServerModel.self)
let context = ModelContext(modelContainer)
self.modelExecutor = DefaultSerialModelExecutor(modelContext: context)
}
public func listServers() throws -> [ServerModel] {
let descriptor = FetchDescriptor<ServerModel>()
return try modelContext.fetch(descriptor)
}
}
When try to call try await MyDatabaseService.shared.listServers()
There are two problems:
ServerModel is not Sendable
"Reference to static property 'shared' is not concurrency-safe because it involves shared mutable state; this is an error in Swift 6"
For the first one, I can solve it by doing:
public struct Server {
let serverUrl: URL;
}
@Model
final public class ServerModel {
@Attribute(.unique) var serverUrl: URL
init(serverUrl: URL) {
self.serverUrl = serverUrl
}
func getSendable() -> Server {
return Server(serverUrl: self.serverUrl)
}
}
@ModelActor
public actor MyDatabaseService {
(...)
public func listServers() throws -> [Server] {
let descriptor = FetchDescriptor<ServerModel>()
return try modelContext.fetch(descriptor).map { $0.getSendable() }
}
}
I am wondering if there is a smarter solution to this first issue. SwiftData already require to define the model with basic/codable types, so if there was a magic way to get a sendable from the model.
I try to make my model 'Codable' but 'Codable' is not compatible with 'Sendable'.
For my second issue, the singleton issue. I do not really know how to fix it.