Post

Replies

Boosts

Views

Activity

Button with symbol SF design like Apple
Hello everyone, I'm working on a fun project for my teacher and want to give my software an Apple-inspired look. Specifically, I'm trying to create image buttons similar to Apple's design (as shown in the image). I need a button with an image that darkens its background when the user hovers over it with the mouse. Any suggestions on how to achieve this effect would be greatly appreciated. For now, I have this code : import SwiftUI struct StudentRow: View { @Environment(\.modelContext) private var modelContext var student: Student @State private var isHover = false var body: some View { HStack { Text(student.name) Image(systemName: "xmark") .opacity(isHover ? 0.9 : 0.1) .bold() .onTapGesture { deleteStudent(student, modelContext: modelContext) } .onHover { hovering in isHover = hovering } } .padding() } } However, I'm not entirely satisfied with the outcome of this code. (Trust me, the outcome is the same when using the magnifying glass icon) plz help
1
0
500
Sep ’24
SwiftUI design elements
Hello everyone, for a personal project I'd like to reproduce a design element from Apple's saving application. I'd like to display three rectangles containing text: two horizontally aligned and one next to it. And I'd like the height of the last rectangle to be equal to the height of the two smallest. Does anyone have a solution? Please provide a sample code
4
0
589
Jul ’24
ForEach and SwiftData Model
Hello World ! I have an issue with a ForEach loop and a SwiftData Model Here is the code : import Foundation import SwiftData @Model final class Todo { var id: UUID var content: String var isDone: Bool var isImportant: Bool var sortValue: Int init(content: String, isDone: Bool, isImportant: Bool) { self.id = UUID() self.content = content self.isDone = isDone self.isImportant = isImportant if isImportant{ self.sortValue = 0 } else { self.sortValue = 1 } } } final class Tag { var id: UUID var content: String init(content: String) { self.id = UUID() self.content = content } } and the content view : import SwiftUI import SwiftData struct AddTodoView: View { @Environment(\.modelContext) private var modelContext @Environment(\.dismiss) var dismiss @Query private var tags: [Tag] @State private var selectedTag: UUID @State private var content: String = "" @State private var isImportant: Bool = false @State private var showAlert: Bool = false @State private var showAchivement: Bool = false var body: some View { TextField("Add a Todo", text: $content) .padding() Toggle(isOn: $isImportant) { Text("Important Todo") } .padding() VStack{ Picker("Tag", selection: $selectedTag) { ForEach(tags, id: \.self){ tag in Text(tag.content) } } } and here is the issue message : Referencing initializer 'init(_:id:content:)' on 'ForEach' requires that 'Tag' conform to 'Hashable'
1
0
979
Nov ’23
Go to a specific View with Button
Hello World ! I figured out some issues in my code : I want to got to a specific view after pressing a button. In fact I cannot use the traditional NavigationLink because I need to do some stuff before. It's like a dismiss function but if I use the @Environment(\.dismiss) var dismiss it goes to the wrong view. So there is my code : Button("Save"){ print("Save") checkCondition() if !showAlert{ addToBase() showAchievement = true Timer.scheduledTimer(withTimeInterval: 1.01, repeats: false) { _ in showExhibitView = true } } } So after the timer I need to display the ExhibitView. Plz Help me !
5
0
787
Oct ’23
UIKit on macOS project
Hello World ! Is UIKit available on macOS project ? I use Firebase package in my project and I encounter this error : SwiftUIPreviewHelpers No such module 'UIKit' This is in the file FirebaseInAppMessaging import UIKit import FirebaseInAppMessaging @available(iOS 13.0, tvOS 13.0, *) @available(iOSApplicationExtension, unavailable) @available(tvOSApplicationExtension, unavailable) public enum InAppMessagingPreviewHelpers { public static func cardMessage(campaignName: String = "Card message campaign", title: String = "Title for modal message", body: String? = "Body for modal message", textColor: UIColor = UIColor.label, backgroundColor: UIColor = UIColor.black, portraitImage: UIImage = UIImage(systemName: "rectangle")!, landscapeImage: UIImage? = UIImage(systemName: "square"), primaryButtonText: String = "Click me!", primaryButtonTextColor: UIColor = UIColor.systemBlue, primaryButtonBackgroundColor: UIColor = UIColor.systemGray, primaryActionURL: URL? = nil, secondaryButtonText: String? = "Dismiss", secondaryButtonTextColor: UIColor? = UIColor.secondaryLabel, secondaryButtonBackgroundColor: UIColor? = UIColor.systemYellow, secondaryActionURL: URL? = nil, appData: [String: String]? = nil) -> ETC Any solutions ?
1
0
793
Sep ’23
Issue with SwiftData on macOS app
I want to make an MacOS app with Swiftdata but there is a problem. When i create a new project and select swiftdata xcode provides example of swiftdata. When I launch the app on my Mac I get the following error in the console: dyld[61569]: Symbol not found: _$s9SwiftData6SchemaC16PropertyMetadataVMa Expected in: <A7F2CF0D-77A3-3F13-BE59-DCBAC4C53133> /System/Library/Frameworks/SwiftData.framework/Versions/A/SwiftData And this : dyld`: 0x7ff8190208a8 <+0>: movl $0x2000209, %eax ; imm = 0x2000209 0x7ff8190208ad <+5>: movq %rcx, %r10 0x7ff8190208b0 <+8>: syscall -> 0x7ff8190208b2 <+10>: jae 0x7ff8190208bc ; <+20> 0x7ff8190208b4 <+12>: movq %rax, %rdi 0x7ff8190208b7 <+15>: jmp 0x7ff818fb50db ; cerror_nocancel 0x7ff8190208bc <+20>: retq 0x7ff8190208bd <+21>: nop 0x7ff8190208be <+22>: nop 0x7ff8190208bf <+23>: nop with the following sentence : Thread 1: signal SIGABRT So my model code is : import Foundation import SwiftData @Model class Paint{ var id: UUID var name: String var heigt: Int var width: Int var category: String var year: String var price: Int var isSold: Bool init(name:String, heigt:Int, width: Int, category: String, year: String, price: Int, isSold : Bool){ self.id = UUID() self.name = name self.heigt = heigt self.width = width self.category = category self.year = year self.price = price self.isSold = isSold } } func addPaint(name:String, heigt:Int, width: Int, category: String, year: String, price: Int, isSold:Bool, context: ModelContext) { let newPaint = Paint(name: name, heigt: heigt, width: width, category: category, year: year, price: price, isSold: isSold) print("item save sucessfully") context.insert(newPaint) } The contentView : import SwiftUI import SwiftData struct ContentView: View { @Environment(\.modelContext) private var context var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") Button("add"){ addPaint(name: "test", heigt: 1, width: 1, category: "", year: "2023", price: 10, isSold: false, context: context) } } .padding() } } and finally the main : import SwiftUI import SwiftData @main struct syhomApp: App { var body: some Scene { WindowGroup { ContentView() } .modelContainer(for: Paint.self) } } please help me !! I have a solution : use CoreData instead but I really want to do it with SwiftData. The thing is and I create a SwiftData projet for iOS every thing is working well (why ?) ...
4
0
741
Sep ’23