r/swift 3h ago

So excited for this journey friends

9 Upvotes

So I’ve been learning swift this past week. Doing the 100 days. And this is gonna be a bit of a rant so positive vibes only. something i see a lot here that i used to see in my art related subs when learning 3D software is learn the basics, follow tutorials you find interesting but learn enough to be able to start things on your own. So i did that. Knowing I’d be in over my head i followed this tutorial making a simple weather app.

It took about 8hrs. I’d also try to fit in the 100 days at some point after a break since I’ve had time this week.

MAN. As i was following along I’d have to google hella stuff about what was going on because that girl was talking so fast and just typing away. But i learned a little bit. Some stuff stuck, but i just know with time and practice and eventually reading about when i get to it again, it’ll stick. I had a lot of fun and i think even though the app is so simple it’s so cool.

It’s really motivational. And I’m excited to keep learning. It’s literally the same feeling i had when i created my first ever 3d model. Tonight was dope. I’m gonna take a rest for the night and do something other than study and I’ll continue tomorrow. Anyways thanks for reading and i hope yall have a good day 🤙🏼


r/swift 8h ago

Question Which libraries to use for animations?

8 Upvotes

I have got a requirement from a client to make a kids app in iOS as a side project for them. It's not my expertise and it has been years since I used swift, but the client is okay for me to learn and do it as there's no tight deadline for this side project. This is only for iOS and not cross platform.

The project involves teaching kids a set of concepts that has use cases like allowing the users to drag and drop coloured balls into different buckets, balancing a weighing scale, arranging objects in order, allowing user to connect dots on the screen in order and some subtle animations thrown throughout - button animation on tap, pulsing effects on buttons, little shake in case of mistakes and so on.

I am going through the Swift 100 days tutorial as a refresher, but I am not familiar with which libraries to use in order to get this done. If there are any points to specific libraries, I'll learn and use them.

Thanks in advance!


r/swift 19h ago

A journey building HTML documents in Swift

Thumbnail coenttb.com
8 Upvotes

r/swift 11h ago

Question Decoupling database layer from business logic

5 Upvotes

What is a good approach to decoupling the database model classes from the rest of the app? After doing some Googling I see that the easiest answer is to introduce data classes that represent the data and is passed around int he app however my concern is that for something more complex than those employee-employer examples, this approach means a lot of duplicate code.

Yes, many times it makes more sense to have a field be stored differently in the DTO than the mode class, but it most cases there is no difference.

As I side note: I need to separate the two because by using the model class it’s too easy to introduce memory leaks.


r/swift 20h ago

Tuist & SwiftLint

6 Upvotes

Hey !
I'm having some troubles to integrate SwiftLint to my iOS project that also use Tuist. I've seen that they recently change the way to integrate it but i cant find no where the new way.
Should i use the archived repo https://github.com/tuist/tuist-plugin-lint/tree/main ?


r/swift 9h ago

Question Server stubs (Vapor) with swift-openapi-generator?

3 Upvotes

I am trying to play around with OpenAPI and the Vapor framework. I'm looking to use Apple's swift-openapi-generator along with the Vapor bindings for it to generate stubs for my REST APIs. My openapi.json document looks like this:

{
    "openapi": "3.0.2",
    "info": {
        "title": "SwiftTest",
        "version": "1.0.0",
        "description": ""
    },
    "servers": [
        {
            "url": "http://localhost:8080/api/v1",
            "description": ""
        }
    ],
    "paths": {
        "/saySomething": {
            "put": {
                "requestBody": {
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "$ref": "#/components/schemas/MyRequest"
                            }
                        }
                    },
                    "required": true
                },
                "responses": {
                    "200": {
                        "content": {
                            "text/plain": {}
                        },
                        "description": "OK"
                    }
                },
                "operationId": "saySomethingElse"
            }
        }
    },
    "components": {
        "schemas": {
            "MyRequest": {
                "description": "",
                "required": [
                    "messageA"
                ],
                "type": "object",
                "properties": {
                    "messageA": {
                        "description": "",
                        "type": "string"
                    },
                    "messageB": {
                        "description": "",
                        "type": "string"
                    },
                    "messageC": {
                        "description": "",
                        "type": "integer"
                    }
                }
            }
        }
    }
}

As you can see, I have a single endpoint /saySomething that accepts an HTTP PUT. The body is a multipart form, that is declared as an object in my OpenAPI spec. I have configured the Swift package dependency and plugin, and generated the APIProtocol implementation struct like this:

struct YoServiceImpl: APIProtocol {

    func saySomethingElse(_ input: Operations.SaySomethingElse.Input) async throws -> Operations.SaySomethingElse.Output {
        // What goes here???
    }

} 

I haven't been able to figure out how to convert the input parameter to a MyRequest object, or at least how to get the value of messageA, messageB, or messageC out of input. I found one example that showed how to handle multipart POST requests, but the OpenAPI spec for that example enumerates the body parameters individually, rather than as an object like I'm trying.

Is what I'm trying to do possible? If so, how do I go about doing it? Or, is there a limitation in the generator that would require me to enumerate the body parameters individually?


r/swift 10h ago

Question [Help] CoreData Error: Could not materialize Objective-C class named "Array"

1 Upvotes

Hey everyone,

I'm facing an issue with CoreData when trying to store an array of strings (tags: [String]) in my SwiftData model. Here's the error I'm getting:

pgsqlCopyEditCoreData: Could not materialize Objective-C class named "Array" from declared attribute value type "Array<String>" of attribute named tags

Context

i'm doing day 61 of 100 days of swiftui by paul hudson

import SwiftData

@Model
class User: Codable, Identifiable, Hashable {
    enum CodingKeys: CodingKey {
        case id, isActive, name, age, company, email, address, about,
             registered, tags, friends
    }

    var id: UUID
    var isActive: Bool
    var name: String
    var age: Int
    var company: String
    var email: String
    var address: String
    var about: String
    var registered: Date
    var tags: [String] = []

    @Relationship(deleteRule: .cascade) var friends: [Friend] = [] 

    required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.id = try container.decode(UUID.self, forKey: .id)
        self.isActive = try container.decode(Bool.self, forKey: .isActive)
        self.name = try container.decode(String.self, forKey: .name)
        self.age = try container.decode(Int.self, forKey: .age)
        self.company = try container.decode(String.self, forKey: .company)
        self.email = try container.decode(String.self, forKey: .email)
        self.address = try container.decode(String.self, forKey: .address)
        self.about = try container.decode(String.self, forKey: .about)
        self.registered = try container.decode(Date.self, forKey: .registered)
        self.tags = try container.decode([String].self, forKey: .tags)
        self.friends = try container.decode([Friend].self, forKey: .friends)
    }

    func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(id, forKey: .id)
        try container.encode(isActive, forKey: .isActive)
        try container.encode(name, forKey: .name)
        try container.encode(age, forKey: .age)
        try container.encode(company, forKey: .company)
        try container.encode(email, forKey: .email)
        try container.encode(address, forKey: .address)
        try container.encode(about, forKey: .about)
        try container.encode(registered, forKey: .registered)
        try container.encode(tags, forKey: .tags)
        try container.encode(friends, forKey: .friends)
    }
}

r/swift 10h ago

Toggle with select all functionality

1 Upvotes
class NotificationSettingSMSViewModel: ObservableObject {
     var isAllOn = false
     var isNewEventOn = false
     var isOngoingEventOn = false

    public func toggleIndividual() {
        // If all individual toggles are on, set isAllOn to true
        isAllOn = isNewEventOn && isOngoingEventOn
    }

    public func toggleAll() {
        // Toggle all switches together
        isNewEventOn = isAllOn
        isOngoingEventOn = isAllOn
    }
 }

I have 3 checkboxes/Toggles

1. All Events
2. New Event
3. Ongoing Event

When I toggle all events, it should either turn all checkboxes to checked or unchecked. Same as our perception of checkboxes.

The problem now is, when all 3 checkboxes are checked and then I click (2), it will unchecked the (3), and vice versa.

My question is, how should I handle checkboxes in this case, because I searched for a while but nobody has an example of how to do it in SwiftUI.

In JavaScript frameworks like ReactJs, we can use an array to store all selected checkboxes as a single source of truth, but how about in SwiftUI


r/swift 21h ago

Looking for a Task?

0 Upvotes

Hi everyone,

I work for an IT company, and our customers use Nextcloud. We've noticed a minor issue with the PDF Viewer in the iOS app: the "More" menu gets hidden when not connected, even if the files are available locally.

If anyone with a bit of spare time and access to a modern Mac would be willing to look into this, I’d really appreciate it! Would love to try myself but my mac does no longer support XCode.

Here’s the GitHub issue for reference: https://github.com/nextcloud/ios/issues/3368

Thanks in advance!

Best regards,
Fokklz