I'm new to developing with SwiftUI and I created a Pomodoro app for macOS that runs in the menu bar. I added 4 animations and when the user selects the snow animation, it starts snowing on the screen. But the app uses 20%-30% of the CPU and has high energy consumption. I can't reduce it and I couldn't find a solution.
// snow animation
import SwiftUI
struct SnowflakeView: View {
@State private var flakeYPosition: CGFloat = -100
@State private var isAnimating = false
private let flakeSize: CGFloat = CGFloat.random(in: 10...30)
private let flakeColor: Color = Color(
red: Double.random(in: 0.8...1),
green: Double.random(in: 0.9...1),
blue: Double.random(in: 1...1),
opacity: Double.random(in: 0.6...0.8)
)
private let animationDuration: Double = Double.random(in: 1...3)
private let flakeXPosition: CGFloat = CGFloat.random(in: 0...310)
var body: some View {
Text("❄️")
.font(.system(size: flakeSize))
.foregroundColor(flakeColor)
.position(x: flakeXPosition, y: flakeYPosition)
.onAppear {
if !isAnimating {
withAnimation(Animation.linear(duration: animationDuration).repeatForever(autoreverses: false)) {
flakeYPosition = 280 + 50
}
isAnimating = true
}
}
}
}
I also have how I run the animation below.
ZStack {
ForEach(0..<10, id: \.self) { index in
if selectedAnimal == "Snow" {
SnowflakeView()
} else if selectedAnimal == "Rain" {
RainDropAnimation()
}else if selectedAnimal == "Leaf"{
LeafFallAnimation()
}else if selectedAnimal == "Confetti"{
ConfettiAnimation()
}
}
}
Explore the art and science of app design. Discuss user interface (UI) design principles, user experience (UX) best practices, and share design resources and inspiration.
Post
Replies
Boosts
Views
Activity
import SwiftUI
import RealmSwift
@main
struct UniqueHolidayApp: App {
init() {
migrateRealmIfNeeded()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
private func migrateRealmIfNeeded() {
let config = Realm.Configuration(
schemaVersion: 1,
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion < 1 {
// Realm will handle changes automatically for simple additions/removals
}
}
)
Realm.Configuration.defaultConfiguration = config
}
}
Hi,
I am implementing the synchronisation of SwiftData with CloudKit as described in the Apple Documentation titled - "Syncing model data across a person’s devices." My app runs fine on iPhone without activating CloudKit under "Signing and Capabilities" option. But when activated, I get a CoreData error with a code: 134060. My app is in development stage. The following is the code snippet for your reference taken from the main structure adopting the App protocol.
init() {
do {
#if DEBUG
let schema = Schema([
Debit.self,
Credit.self,
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
// Use an autorelease pool to make sure Swift deallocates the persistent
// container before setting up the SwiftData stack.
try autoreleasepool {
let desc = NSPersistentStoreDescription(url: modelConfiguration.url)
let opts = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.com.sureshco.MyFirstApp")
desc.cloudKitContainerOptions = opts
// Load the store synchronously so it completes before initializing the CloudKit schema.
desc.shouldAddStoreAsynchronously = false
if let mom = NSManagedObjectModel.makeManagedObjectModel(for: [
Debit.self,
Credit.self,
]) {
let container = NSPersistentCloudKitContainer(name: "MyFirstApp", managedObjectModel: mom)
container.persistentStoreDescriptions = [desc]
container.loadPersistentStores {_, err in
if let err {
fatalError(err.localizedDescription)
}
}
// Initialize the CloudKit schema after the store finishes loading.
try container.initializeCloudKitSchema()
// Remove and unload the store from the persistent container.
if let store = container.persistentStoreCoordinator.persistentStores.first {
try container.persistentStoreCoordinator.remove(store)
}
}
}
#endif
sharedModelContainer = try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError(error.localizedDescription)
}
}
Any help will be greatly appreciated!
Regards
Suresh.
I am experiencing strange crashes in my (ObjC) code, that insinuate some memory corruption (mostly running SHA256 decryption for file data
in my code there's a
// return object that was stored in encrypted file
- (id) objectFromEncryptedFile:(NSString *)filePath
{
// read MYCrypto object that includes encrypted object of any class
MYCrypto *encData = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
// decrypt, unarchive and return
return [encData objectFromEncryptedData:encData.data];
}
That seems to be called from different queues that are not synchronized.
It came to me that maybe NSKeyedUnarchiver is not "thread safe" and maybe unarchiveObjectWithFile is not reentrant?
Couldn't find anything in the normal documentation, but most of the old docs are no longer searchable.
Can someone shed light on this?
I am seeking guidance regarding the inclusion of app branding on the navigation controller across all screens within our application. Although it appears that Apple doesn't typically recommend this practice, our client has specifically requested the addition of branding elements.
Can you please advise if it is permissible to implement such branding, and whether doing so would affect the app review process?
The apple guideline state:
"Ensure branding always defers to content. Using screen space for an element that does nothing but display a brand asset can mean there’s less room for the content people care about. Aim to incorporate branding in refined, unobtrusive ways that don’t distract people from your experience."
Source: https://developer.apple.com/design/human-interface-guidelines/branding
Hi,
I am developing an application using Flutter to connect to a Bluetooth Classic device (device is also developed by me), as Flutter is multi-platform I have tested this functionality in Android devices and it works fine, but when I want to develop the functionality of scanning BT devices, connect and send commands it is not possible due to I haven't found classic BT libraries to make this actions for iOS, do you know any library? There is any reason why isn't it possible?
Hello I’m here to post my recent updates errors and bugs on iOS 18.2
After installing after few hours my screen display was flashing like thunder I notice two times first I tot its video second time realised it was error
after that screen got green color and brightness increased
when check with settings black screen became green.
i tried calling customer support they asked me to backup the device and turn off beta updates and reinstall the software using computer.
but I don’t want to downgrade becoz I got lost gbs of photos videos and some datas stored on app sometimes I can backup and restore photos and video but I don’t want to miss out other important datas stored on app specially. Please some one help me and suggest me how to downgrade to iOS 18.1
another question shall wait for next update coming in December while waiting any damage will happen to my screen display or to my battery?? Pls help me
The app or its metadata appears to contain potentially misleading content. Specifically, the app includes content that resembles AlphaCargo without the necessary authorizatin.