Post

Replies

Boosts

Views

Activity

Getting Preview Crashed with the Red X
I am getting Preview Crash. If I remove line 30 below. then the Preview Crash does not occur. I have Restarted XCode, I have done a Project Clean, Then did a project rebuild. I have also Created a new Project from scratch Named the project Debug, Add one new View File named MaskBootCamp once I select MaskBootCamp The Preview willl Crash with an Circle with a Red X in the center With Preview Crashed. If I remove line 22 all is resolved and no exception occurs Is this a Swift Bug or some error in the coding? Excepition Report listed below the code. report Below: ** MaskBootCamp .swift ** import SwiftUI struct MaskBootCamp: View { @State var rating: Int = 0 var body: some View { ZStack{ starsView .overlay(overlayView.mask(starsView)) } } private var overlayView: some View { GeometryReader { geometry in ZStack(alignment: .leading) { Rectangle() .foregroundColor(.yellow) .frame(width: CGFloat(rating) / 5 * geometry.size.width) } //allowsHitTesting(false) } } private var starsView: some View { HStack{ ForEach(1..<6) {index in Image(systemName: "star.fill") .font(.largeTitle) .foregroundColor(.gray) .onTapGesture { rating = index } } } } } #Preview { MaskBootCamp() }
3
0
637
Dec ’23
Having issues with SwiftUI ForEach usage
The code below is a json parser example. I used the quick type website to build my structs for reading in the json. All that code works but I am having an issue with looping thru the data read. I am trying to read this is a view, so I can not use a for statement. I am having issues learning how to use the ForEach Statement to loop on the contacts in this json data and print the firstName, lastName for each contact. This is the Code let data1JSON = """ [ { "data": { "viewer": { "__typename": "Member", "id": 123, "firstName": "d", "lastName": "a", "emailAddress": "w" }, "league": { "id": 1111, "name": "a", "slug": "b", "isMine": true, "logo": "g", "homePageUrl": "bA", "facebookUrl": "www.facebook.com/B", "phone": "1", "contacts": [ { "id": 12, "firstName": "", "lastName": "d", "phone": null, "__typename": "Contact" }, { "id": 10, "firstName": "", "lastName": "c", "phone": null, "__typename": "Contact" } ], "__typename": "League" } } } ] """ // MARK: - ApaResultElement struct ApaResultElement: Codable { let data: DataClass } // MARK: - DataClass struct DataClass: Codable { let viewer: Viewer let league: League } // MARK: - League struct League: Codable { let id: Int let name, slug: String let isMine: Bool let logo: String let homePageURL, facebookURL, phone: String let contacts: [Viewer] let typename: String enum CodingKeys: String, CodingKey { case id, name, slug, isMine, logo case homePageURL = "homePageUrl" case facebookURL = "facebookUrl" case phone, contacts case typename = "__typename" } } // MARK: - Viewer struct Viewer: Codable { let id: Int let firstName, lastName: String let phone: JSONNull? let typename: String let emailAddress: String? enum CodingKeys: String, CodingKey { case id, firstName, lastName, phone case typename = "__typename" case emailAddress } } typealias ApaResult = [ApaResultElement] // MARK: - Encode/decode helpers class JSONNull: Codable, Hashable { public static func == (lhs: JSONNull, rhs: JSONNull) -> Bool { return true } public var hashValue: Int { return 0 } public init() {} public required init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() if !container.decodeNil() { throw DecodingError.typeMismatch(JSONNull.self, DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Wrong type for JSONNull")) } } public func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() try container.encodeNil() } } let decoder = JSONDecoder() let leagueView = data1JSON.data(using: .utf8)! do { try decoder.decode([ApaResultElement].self, from: leagueView) print("success") } catch { print("Error found => \(error)") } let d1 = try decoder.decode([ApaResultElement].self, from: leagueView) // This is where I need help to loop the json to extract all the data // I see that I need to loop on each array stuct to do that. I have looked for a good tutorial on ForEach, but none of the sites I found help me look on this JSON Data. I am new to swift and the autocomplete feature, so any tips using Apple Developer Documentation or the Code Complete would also be appreciated. Thanks
2
0
1.2k
Dec ’23
Warning: color asset name resolves to a conflicting Color symbol
I have created a IOS Application in XCode 15.2 (15C500b) which causes issue not able to see previews. In the Assets.xcassets folder I have created a ThemeColors which contains 5 Color Sets. I had used these in another Swift Project, and also used these same color sets in the second project. The First Project name was WC. The Second Project name is WCCardDemo stored in a different project folder. Now when I copy or retype these color sets into the Project WCCardDemo, I get the following warnings in Multiline ^ WCCardDemo X Command compiledAssetCatalog failed with nonzero exit code The "GreenColor" color asset name resolves to a conflicting UI symbol "green. Try renaming the asset. The "RedColor" color asset name resolves to a conflicting UI symbol "red. Try renaming the asset. BlockQuote When I try to refresh the startup default ContentView I get Failed to build the scheme WC Content View import SwiftUI struct ContentView: View { var body: some View { ZStack { Color.theme.background.ignoresSafeArea() VStack { Text("Accent Color") .foregroundColor(Color.theme.accent) Text("Seconday Text Color") .foregroundColor(Color.theme.secondaryText) Text("Red Color") .foregroundColor(Color.theme.red) Text("Green Color") .foregroundColor(Color.theme.green) } } .padding() } } #Preview { ContentView() } code-block I also get the GeneratedAssetSymbols file displayed !! <GeneratedAssetSymbols.swift> ... extension DeveloperToolsSupport.ColorResource { ... /// The "BacktgroundColor" asset catalog color. static var backtground: UIKit.UIColor { #if !os(watchOS) .init(resource: .backtground) #else .init() #endif } #warning("The \"GreenColor\" color asset name resolves to a conflicting UIColor symbol \"green\". Try renaming the asset.") #warning("The \"RedColor\" color asset name resolves to a conflicting UIColor symbol \"red\". Try renaming the asset.") code-block This appears to me to be xCode bug, and not a coding issue. I am asking if reusing assets and color sets File names in multple swift projects is bad practice. This does not make sense to me, that I can not reuse color set files ???. The first time I used the RedColor colorset name it was no issue. If i use it again in another separate Swift Project I get compile errors ??? Clean project does not fix this issue. Thanks in Advance for any Information of best pratices, or what issue I am having.
3
0
1.4k
Jan ’24
Drag and Drop Animation with 4 animation effects
Hey Forum friends. I am an new IOS Developer and have been working on SwiftUI for about 2 months. I am working on developing a Swift UI App and I have the desire to produce a drag and drop animation effect for a sports type application. This is not a game but a user drag drop interface to make a selection tool where selecting an option is a little more game like. Like putting a ball to select 1 of six options provided on the sheet. So the simple design is as follows. The user has a sheet open which has a small solid blue circle shape which can be dragged using gesture(DragGesture()). In Playing around with this circle I was experimenting with trying to drag the blue circle like a marble so that it rolls for a defined distance to follow the direction (vector) for a distance where it would appear to roll like a marble till it hit an option target in either the top left or top right corner of the screen. I had the thought that maybe there may be a possible code design to implement this in a SwiftUI sheet via a drag animation effect. So another advanced example of what I am working at. You have a 6 black round circle on a UI Sheet in six positions on a rectangle, resembling pockets on a pool table. in the center of the pool table you have a blue circle representing a pool ball The user touches the circle using a gesture and flick it toward toward one of the 6 pool pockets on the screen to select one of the six options represented on the sheet. If the user did not hit the correct pocket option, then a reset button could reset the sheet for another attempt. The idea behind this is to make the selection process more fun and exciting. I realize this might not be possible without using something like sprites. I had the idea while animating a chart graph, where the chart line was drawn for let to right on the screen in a 3 second animation. I suspect this might be possible using drag and drop. Thanks for any suggestions for creating this design in an IOS App.
0
0
487
Mar ’24
How to invoke an Apple Iphone to take screen shot
I am working on an application design where I would like to have the Iphone running an app such as Apple Map, and while I might be driving in the car I would like to have my apple Watch invoke a screen shot of the current view of I map showing my location without having to use the iphone. So the Iphone would be active and in a car holder displaying my location on the map. Once I made my route point, such as a waypoint. I would like to press a button on my watch app to do a screen print. Second though is, could I press a button on my Apple Watch app to fire an request to my own IOS Application using WatchConnectivity to capture my Location to a data file. Third thought is could a press a button on my Apple Watch app to interact with an active app, which is an app like a reminder app and create a new Reminder Note in the active app in focus on my Iphone, but is not a component of my IPhone App. Thanks for any insight how I could make a Apple Watch app send Button Presses reliably to my Iphone Application active, so that I. could avoid having to touch my iPhone? Thanks in advance for any guidance.
0
0
602
Mar ’24
My Apple Watch is not available as a build destination for xcode
A few days ago I was able to build to my apple watch which is paired to my iphone. I upgraded to the current release of IOS which is 17.4.1. I also updated my apple watch to 10.4. Once I completed these updates I had issue where the watch was running 10.4, but when I. viewed the apple watch using manage run destinations. It still said 10.1 I unplugged the iphone from mac a few times, restarted XCode but still could not use the apple watch to build a 10.4 build to it. I did my basic research and read that you also you might need to reboot the mac. After some time i decided to break the trust with my mac and apple watch, then since that time I have not been able to view it in the device list. Next steps taken, was to unpair the apple watch from my I phone and repair. Next on the Iphone I cleared trusted devices. Then I attached my iphone to the mac, and retrusted my iphone and apple watch. I also have the mac up to the newest version Sonoma 14.4.1 Xcode can see my IPhone, but not the watch xcrun devicectl list devices shows Devices: Name Hostname Identifier State Model Barry's IPhone 14 Pro Barrys-IPhone-14-Pro.coredevice.local xxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxA209B connected iPhone 14 Pro (iPhone15,2) Manage Run Destinations shows my IPhone details but still does not show any paired devices. I have made sure that the watch is in Developer Mode I have Associated Domains Developement enabled WidgetKit Developer Mode is disabled What would be my next steps in resolving this issue? Thanks
1
0
755
Apr ’24
How to store Public Data in ICloud
I have been working on an ios application which I decided to use the new SwiftData architecture, and I now have realized that SwiftData does not support public or shared databases using SwiftData. I am a new and upcoming Swift developer, who has been self learning the Apple Swift technology. I just learned in this forum that Swift Data does not support Public and Shared Data and I also understand that no plans that have been announced to addressed this feature in the IOS 18 release time frame. The use case for my application is to implement a social type application, something like applications including X, facebook, etc. These type of applications appear to use Public, Shared and Private data in various existing Apple application. I would like to complete an application using Swift using ICloud, but I must assume that these current social applications are using other technologies. I am assuming you can do this in Core Data, but my understanding is Apple is asking that we use Swift Data to replace core data. I also am assuming that Swift data is built on core data technology layers. So ... to me it seems hopeful, somehow, to accomplish this using IOS 17 and follow the recommend Swift Data Path. What are my options for completing these data objectives in IOS? I hope I am addressing these questions in the proper and best forum? Much thanks for any suggestions.
3
1
973
May ’24
Ghost Complile Error and other odd project issues
In my project I had made the following code block I changed //ToolbarItemGroup(placement: .topBarTrailing) to ToolbarItemGroup(placement: .topBarLeading) because I got a compile error. Then I started having the effect of everytime I did a Clean then Rebuild I would get the following Error /Users/barrywest/Desktop/Apple Development/AppleTutorials/APAJSONReader/APAJSONReader/View/SchemaMaintenance/SchemaDetail.swift:149:42 'navigationBarTrailing' is unavailable in macOS once clicked it would hightlight the commeted out code. then the error would magically go away after clicking on the error If you do not click the error it would stay, even if you ran the code it would display but the simulator would run instead of getting an error I then delete the comment, but I still get the ghost complile error with the same effect. I continued to make changes, and now the I get a different older display on the simulator, as compared to my Preivew Display. The colors seem to have gotten saved in the Run Simulator, even after Clean Build, Recompile... I still get the ghost error which has been removed and the new Executable still contains ghost code which shows incorrect colors. I can have the simulator and preview view running at the same time with different View Colors... I have closed the project and reopend the project with no Changes. My guess is some kind of file corruption somewhere ... import SwiftUI import SwiftData struct SchemaDetail: View { @Environment(\.modelContext) var dbContext ... var body: some View { VStack { switch schemaName { case .leagues: switch displayCategory { case .full: leagueFullDisplay case .brief: leagueBriefDisplay case .edit: leagueEdit case .create: leagueCreate } ... } //Text(schemaName.localizedName) } .navigationTitle(schemaName.localizedName) .toolbar { ** //ToolbarItemGroup(placement: .topBarTrailing)** ToolbarItemGroup(placement: .topBarLeading) { switch displayCategory { case .full: Button(action: { }, label: { Image(systemName: "minus.magnifyingglass") }) Button(action: { }, label: { Image(systemName: "doc.badge.plus") }) Button(action: { // Preload from json Warning may be about using background thread ??? Task(priority: .background) { loadLeagues() } }, label: { Image(systemName: "folder.fill.badge.gearshape") }) case .brief: Button(action: { }, label: { Image(systemName: "plus.magnifyingglass") }) Button(action: { }, label: { Image(systemName: "doc.badge.plus") }) case .create: Button(action: { }, label: { Image(systemName: "square.and.arrow.down.fill") }) Button(action: { }, label: { Image(systemName: "arrowshape.turn.up.backward.circle.fill") }) case .edit: Button(action: { }, label: { Image(systemName: "square.and.arrow.down.fill") }) Button(action: { }, label: { Image(systemName: "arrowshape.turn.up.backward.circle.fill") }) } } } } } #Preview { SchemaDetail(schemaName: LeagueCategory.sessions, displayCategory: DisplayCategory.brief) }
2
0
369
Aug ’24