Releases: HuskyXaHusky/UCgorgeous
v1.02
@GetCaseName was added
A macro that adding computed property caseName
and Name
enumeration within enum
.
Name
enumeration is used to represent the names of the cases in the enum
.
Overall, macro adds functionality to easily get the name of the current case in the complex enumeration,
each case of which contains other enumerations, complex classes or structures, which is extremely useful
in many situations and simply irreplaceable when you need to know which case is currently being used in order to set
a condition without unnecessary clarification of the parameters of the object contained in this case.
1.01a
The documentation has been updated to reflect "Inconsistent initialization error" (issue 3)
v1.01
- The former Copy method was divided into two subtypes.
- Documentation has been updated and improved.
v1.00
StructCopy
A macro that adding method copy
to a struct
.
The copy
method allows creating a new struct
with customized property values while retaining the original
other values.
This way, you don't have to create a new struct
and fill out its "fields" if you want to change one or a couple values.
The more values there are in the struct
, the more useful the method provided by the macro will be.
Please note that computed properties are ignored!
For example,
@StructCopy
struct Settings: Equatable, Hashable {
let pinned: [ String ]
let customNames: [ String : String ]
let id: Int?
var pinsCount: Int {
return pinned.count
}
}
produce method:
func copy(pinned: [ String ]? = .none, customNames: [ String : String ]? = .none, id: Int?? = .none) -> Settings {
Settings(pinned: pinned ?? self.pinned, customNames: customNames ?? self.customNames, id: id ?? self.id)
}
Usage:
let oldSettings = Settings(pinned: ["1", "2"], customNames: ["07245724": "Rofl"], id: nil)
let newSetting = oldSettings.copy(id: 120)
ClassCopy
A macro that adding method copy
to a class
.
The copy
method allows creating a new instance of the class
with customized property values while retaining the original
instance's other values.
This way, you don't have to create a new instance of a class
and fill out its "fields" if you want to change one or a couple values.
The more values there are in the class
, the more useful the method provided by the macro will be.
Please note that computed properties are ignored!
For example,
@ClassCopy
final class MainState {
var onlineStatus: String? = "online"
var chats: [String] = []
var chatsDict: [String:String] = [:]
var chatsCount: Int {
return chats.count
}
}
produce method:
func copy(onlineStatus: String?? = .none, chats: [String]? = .none, chatsDict: [String: String]? = .none) -> MainState {
let result = MainState()
result.onlineStatus = onlineStatus ?? self.onlineStatus
result.chats = chats ?? self.chats
result.chatsDict = chatsDict ?? self.chatsDict
return result
}
Usage:
let oldState = MainState()
let newState = oldState.copy(chats: ["MainChat", "P2PChat", "HolyWarPublicChat"])
GetColor
A macro that adding method that returns the color
associated with the capitalized
enum case
.
When the method is called on an instance of the enum, it returns the corresponding color object.
This allows for easy access to a set of predefined colors in the application. For example,
@GetColor
enum ColorSet {
case red
case green
case megaCustomColorInAsset
}
produce method:
var color: Color {
switch self {
case .red:
return Color("Red")
case .green:
return Color("Green")
case .megaCustomColorInAsset:
return Color("MegaCustomColorInAsset")
}
}
when need color:
Color(ColorSet.megaCustomColorInAsset.color)
v1.02-alpha
Now @ClassCopy and @StructCopy completely ignore computed properties.