Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift module name breaks things #387

Closed
mitchins opened this issue Mar 18, 2020 · 1 comment
Closed

Swift module name breaks things #387

mitchins opened this issue Mar 18, 2020 · 1 comment

Comments

@mitchins
Copy link
Contributor

mitchins commented Mar 18, 2020

Expected Behavior

Default (implicit/empty) module name should not cause machine filename to be '__' and human filename '_'.

Likewise the customSuperentity shouldn't start with a '.' in same scenario.

Actual Behavior

In the case of the default module: Current Product Module under Xcode "Class" options,
the managedObjectClassName has a leading '.' which is currently escaped to ''. In in the case of a leading '.', we should isolate it before conversion to '' because if the module name is missing.

This is a simple check and I will raise a PR.

Additionally the customSuperentity is prefixing the super class with a '.', again we can sanitise this just like we do for sanitizedManagedObjectClassName.

Further details:

Here are the options for module in the core data editor.

image

This is what the default template with current release version of mogenerator produce

➜  freemote-app git:(master) ✗ mogenerator --version
mogenerator 1.32. By Jonathan 'Wolf' Rentzsch + friends.
➜  freemote-app git:(master) ✗ ls -lh /Users/mitchellcurrie/Projects/freemote-app/Freemote/Shared/Persistence/Models-Autogen
total 80
-rw-r--r--@ 1 mitchellcurrie  staff    98B 19 Mar 10:03 _Gateway.swift
-rw-r--r--@ 1 mitchellcurrie  staff   146B 19 Mar 10:03 _HomeAssistantConnection.swift
-rw-r--r--@ 1 mitchellcurrie  staff    95B 19 Mar 10:03 _KeyMap.swift
-rw-r--r--@ 1 mitchellcurrie  staff   104B 19 Mar 10:03 _MappedKey.swift
-rw-r--r--@ 1 mitchellcurrie  staff   113B 19 Mar 10:03 _TargetDevice.swift
-rw-r--r--@ 1 mitchellcurrie  staff   2.2K 19 Mar 10:03 __Gateway.swift
-rw-r--r--@ 1 mitchellcurrie  staff   1.5K 19 Mar 10:03 __HomeAssistantConnection.swift
-rw-r--r--@ 1 mitchellcurrie  staff   3.7K 19 Mar 10:03 __KeyMap.swift
-rw-r--r--@ 1 mitchellcurrie  staff   1.7K 19 Mar 10:03 __MappedKey.swift
-rw-r--r--@ 1 mitchellcurrie  staff   1.7K 19 Mar 10:03 __TargetDevice.swift

Here is the contents of __HomeAssistantConnection.swift (machine file)

// DO NOT EDIT. This file is machine-generated and constantly overwritten.
// Make changes to HomeAssistantConnection.swift instead.

import Foundation
import CoreData

public enum HomeAssistantConnectionAttributes: String {
    case entityID = "entityID"
    case host = "host"
    case token = "token"
}

open class _HomeAssistantConnection: .Gateway {

    // MARK: - Class methods

    override open class func entityName () -> String {
        return "HomeAssistantConnection"
    }

    override open class func entity(managedObjectContext: NSManagedObjectContext) -> NSEntityDescription? {
        return NSEntityDescription.entity(forEntityName: self.entityName(), in: managedObjectContext)
    }

    @nonobjc
    open class func fetchRequest() -> NSFetchRequest<HomeAssistantConnection> {
        return NSFetchRequest(entityName: self.entityName())
    }

    // MARK: - Life cycle methods

    public override init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
        super.init(entity: entity, insertInto: context)
    }

    public convenience init?(managedObjectContext: NSManagedObjectContext) {
        guard let entity = _HomeAssistantConnection.entity(managedObjectContext: managedObjectContext) else { return nil }
        self.init(entity: entity, insertInto: managedObjectContext)
    }

    // MARK: - Properties

    @NSManaged open
    var entityID: String!

    @NSManaged open
    var host: URL?

    @NSManaged open
    var token: String?

    // MARK: - Relationships

}

Notice the .Gateway as the super class of _HomeAssistantConnection (presumably because the module is inferred default, but it KNOWS it has a module). The PR I open will allow for a sanitised version of the name of the super class (but still maintain the existing one so as to not break things that work already).

Tagging @rentzsch
PS.
Fully specifying the module name results in both the files and classes being fully qualified which generally breaks things even worse.

Edit: It's also necessary (my case here) to use the current module instead of global because it seems to break some things in SwiftUI if we don't:
See other post here

rentzsch added a commit that referenced this issue Jul 6, 2020
Address #387, "Current Product Module" issues with swift/Xcode-11.3
@rentzsch
Copy link
Owner

rentzsch commented Jul 6, 2020

Closed by #388.

@rentzsch rentzsch closed this as completed Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants