Post

Replies

Boosts

Views

Activity

Reply to When decoding a Codable struct from JSON, how do you initialize a property not present in the JSON?
I've also encountered this problem in my own framework ColorKit I downloaded a 450000 line JSON database from GitHub and found out it has no id while my SingleColor model is Identifiable AHHHHH So I went to to add id to them one by one for a couple of days and realized I could actually create a struct that's without the id called the SingleColorInit and load the JSON into this model and then casting all of my data into my SingleColor model. Code: public struct SingleColorInit: Codable, Hashable{ public var name: String public var hex: String public var rgb: RGBList public var hsl: HSLList public var luminance: Double } public struct SingleColor: Codable, Hashable, Identifiable{ public var id: UUID = UUID() public var name: String public var hex: String public var rgb: RGBList public var hsl: HSLList public var luminance: Double } let coloKey: [InitColor] = load("database.json") public func database() -> [SingleColor] { var returnData: [SingleColor] = [] for datum in colorKey { returnData.append(SingleColor(name: datum.name, hex: datum.hex, rgb: datum.rgb, hsl: datum.hsl, luminance: datum.luminance)) } returnData.remove(at: 0) return returnData } so when I create a new instance of the object the UUID will be generated. In your case you can do this: struct InitReminder {     var title: String     var dueDate: Date     var notes: String? = nil     var isComplete: Bool = false } struct Reminder: Identifiable {     var id: String = UUID().uuidString     var title: String     var dueDate: Date     var notes: String? = nil     var isComplete: Bool = false } // load your data (I use the load method in Apple's SwiftUI tutorial) let reminders: [Reminder] = load("youdatabase.json") func database() -> [Reminder] {     var returnData: [Reminder] = []     for datum in reminders{         returnData.append(Reminder(title: datum.title, dueDate: datum.dueDate, notes: datum.notes, isComplete: datum.isComplete))     }     return returnData } And then I realized... When you use your data in a SwiftUI(if you use it) List or ForEach, you don't need it to be Identifiable; use each item's self as the id. Just do this: List(yourData, id: \.self) { item in ... } ForEach(yourData, id: \.self) { item in ... } This is problem has annoyed me long time really😂 I'm really happy to share this solution to someone who need it It's really annoying hope it'll help
Topic: Programming Languages SubTopic: Swift Tags:
May ’22
Reply to How to distribute a private Xcode app to a few friends
I too music student written a app for my piano teacher realizing I didn't have a developer license or other ways to distribute it and I'm in COVID lockdown so I couldn't let my teacher come to my home and upload it to her phone as in a physical device run😂 (Hey that's a way if you can) just joking I'll guess you have a developer account. if you have a developer account you have a Developer ID option when archiving your app it says that you can distribute directly to your costumers Also If you find a way to distribute iOS or WatchOS or TVOS app to costumers without using a developer account email me "makabaka1880@outlook.com" Hope it'll help😄
May ’22
Reply to How to create .saver file?
If you create a new Xcode project that's a option "Screen Saver" If you have ever noticed, but, it's in Objective-C🙁(which I can give no suggestions on) But if you integrate Xcode toolchain(if you can find it) into your app and learn about OC, maybe you can make a app that will compile your user's input into OC Code, then if you can, compile the OC code into .saver. But this is really a good app idea but really, really hard.
Topic: App & System Services SubTopic: Core OS Tags:
May ’22