Skip to content

Commit 1d11253

Browse files
committed
Optimized Initializers
1 parent c2fd23f commit 1d11253

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+223
-188
lines changed

Sources/KintoneAPI/Codable/NumberPrecision.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public struct NumberPrecision: Codable, Sendable, Equatable {
3030
try container.encode(roundingMode, forKey: .roundingMode)
3131
}
3232

33-
init(digits: Int, decimalPlaces: Int, roundingMode: RoundingMode) {
33+
init(
34+
digits: Int,
35+
decimalPlaces: Int,
36+
roundingMode: RoundingMode
37+
) {
3438
self.digits = digits
3539
self.decimalPlaces = decimalPlaces
3640
self.roundingMode = roundingMode

Sources/KintoneAPI/Decodable/AppSettings/TitleField.swift

-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,4 @@
88
public struct TitleField: Decodable, Sendable, Equatable {
99
public var selectionMode: TitleFieldSelectionMode
1010
public var code: String
11-
12-
init(selectionMode: TitleFieldSelectionMode, code: String) {
13-
self.selectionMode = selectionMode
14-
self.code = code
15-
}
1611
}

Sources/KintoneAPI/Decodable/AppStatus/Assignee.swift

-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,4 @@
88
public struct Assignee: Decodable, Sendable, Equatable {
99
public var type: AssigneeType
1010
public var entities: [AssigneeEntity]
11-
12-
init(type: AssigneeType, entities: [AssigneeEntity]) {
13-
self.type = type
14-
self.entities = entities
15-
}
1611
}

Sources/KintoneAPI/Decodable/AppStatus/AssigneeEntity.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public struct AssigneeEntity: Decodable, Sendable, Equatable {
2525
includeSubs = try container.decode(Bool.self, forKey: .includeSubs)
2626
}
2727

28-
init(type: EntityType, code: String?, includeSubs: Bool) {
28+
init(
29+
type: EntityType,
30+
code: String?,
31+
includeSubs: Bool
32+
) {
2933
self.type = type
3034
self.code = code
3135
self.includeSubs = includeSubs

Sources/KintoneAPI/Decodable/AppStatus/RecordState.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public struct RecordState: Decodable, Sendable, Equatable {
2323
assignee = try container.decode(Assignee.self, forKey: .assignee)
2424
}
2525

26-
init(name: String, index: Int, assignee: Assignee) {
26+
init(
27+
name: String,
28+
index: Int,
29+
assignee: Assignee
30+
) {
2731
self.name = name
2832
self.index = index
2933
self.assignee = assignee

Sources/KintoneAPI/Decodable/AppStatus/StatusAction.swift

-7
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,4 @@ public struct StatusAction: Decodable, Sendable, Equatable {
1717
case to
1818
case filterCondition = "filterCond"
1919
}
20-
21-
init(name: String, from: String, to: String, filterCondition: String) {
22-
self.name = name
23-
self.from = from
24-
self.to = to
25-
self.filterCondition = filterCondition
26-
}
2720
}

Sources/KintoneAPI/Decodable/Comment/RecordComment.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ extension RecordComment {
3636
mentions = try container.decode([Entity.Read].self, forKey: .mentions)
3737
}
3838

39-
init(id: Int, text: String, createdAt: Date, creator: Entity.Read, mentions: [Entity.Read]) {
39+
init(
40+
id: Int,
41+
text: String,
42+
createdAt: Date,
43+
creator: Entity.Read,
44+
mentions: [Entity.Read]
45+
) {
4046
self.id = id
4147
self.text = text
4248
self.createdAt = createdAt

Sources/KintoneAPI/Decodable/Common/Entity+Read.swift

-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,5 @@ extension Entity {
1010
public var type: EntityType
1111
public var code: String
1212
public var name: String?
13-
14-
init(type: EntityType, code: String, name: String?) {
15-
self.type = type
16-
self.code = code
17-
self.name = name
18-
}
1913
}
2014
}

Sources/KintoneAPI/Decodable/Common/File+Read.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ extension File {
2727
fileSize = try container.decode(String.self, forKey: .fileSize)
2828
}
2929

30-
init(fileKey: String, mimeType: String, fileName: String, fileSize: String) {
30+
init(
31+
fileKey: String,
32+
mimeType: String,
33+
fileName: String,
34+
fileSize: String
35+
) {
3136
self.fileKey = fileKey
3237
self.mimeType = mimeType
3338
self.fileName = fileName

Sources/KintoneAPI/Decodable/FetchAppSettingsResponse.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,21 @@ public struct FetchAppSettingsResponse: Decodable, Sendable, Equatable {
5353
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
5454
}
5555

56-
init(name: String, description: String, icon: AppIcon.Read, theme: AppThemeType, titleField: TitleField, enableThumbnails: Bool, enableBulkDeletion: Bool, enableComments: Bool, enableDuplicateRecord: Bool, enableInlineRecordEditing: Bool, numberPrecision: NumberPrecision, firstMonthOfFiscalYear: Int, revision: Int) {
56+
init(
57+
name: String,
58+
description: String,
59+
icon: AppIcon.Read,
60+
theme: AppThemeType,
61+
titleField: TitleField,
62+
enableThumbnails: Bool,
63+
enableBulkDeletion: Bool,
64+
enableComments: Bool,
65+
enableDuplicateRecord: Bool,
66+
enableInlineRecordEditing: Bool,
67+
numberPrecision: NumberPrecision,
68+
firstMonthOfFiscalYear: Int,
69+
revision: Int
70+
) {
5771
self.name = name
5872
self.description = description
5973
self.icon = icon

Sources/KintoneAPI/Decodable/FetchAppStatusSettingsResponse.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by ky0me22 on 2025/01/31.
66
//
77

8+
import Foundation
9+
810
public struct FetchAppStatusSettingsResponse: Decodable, Sendable, Equatable {
911
public var enable: Bool
1012
public var states: [RecordState]
@@ -28,12 +30,18 @@ public struct FetchAppStatusSettingsResponse: Decodable, Sendable, Equatable {
2830
states = try statesContainer.allKeys.map { key in
2931
try statesContainer.decode(RecordState.self, forKey: DynamicCodingKey(stringValue: key.stringValue)!)
3032
}
33+
.sorted(using: KeyPathComparator(\.index))
3134
}
3235
actions = try container.decodeIfPresent([StatusAction].self, forKey: .actions) ?? []
3336
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
3437
}
3538

36-
init(enable: Bool, states: [RecordState], actions: [StatusAction], revision: Int) {
39+
init(
40+
enable: Bool,
41+
states: [RecordState],
42+
actions: [StatusAction],
43+
revision: Int
44+
) {
3745
self.enable = enable
3846
self.states = states
3947
self.actions = actions

Sources/KintoneAPI/Decodable/FetchAppsResponse.swift

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77

88
public struct FetchAppsResponse: Decodable, Sendable, Equatable {
99
public var apps: [KintoneApp]
10-
11-
init(apps: [KintoneApp]) {
12-
self.apps = apps
13-
}
1410
}

Sources/KintoneAPI/Decodable/FetchFieldsResponse.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ public struct FetchFieldsResponse: Decodable, Sendable, Equatable {
1919
public init(from decoder: any Decoder) throws {
2020
let container = try decoder.container(keyedBy: CodingKeys.self)
2121
let fieldsContainer = try container.nestedContainer(keyedBy: DynamicCodingKey.self, forKey: .fields)
22-
fields = try fieldsContainer.allKeys
23-
.map { try fieldsContainer.decode(Field.self, forKey: DynamicCodingKey(stringValue: $0.stringValue)!) }
24-
.sorted(using: KeyPathComparator(\.code))
22+
fields = try fieldsContainer.allKeys.map {
23+
try fieldsContainer.decode(Field.self, forKey: DynamicCodingKey(stringValue: $0.stringValue)!)
24+
}
25+
.sorted(using: KeyPathComparator(\.code))
2526
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
2627
}
2728

28-
init(fields: [Field], revision: Int) {
29+
init(
30+
fields: [Field],
31+
revision: Int
32+
) {
2933
self.fields = fields
3034
self.revision = revision
3135
}

Sources/KintoneAPI/Decodable/FetchFormLayoutResponse.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public struct FetchFormLayoutResponse: Decodable, Sendable, Equatable {
2020
revision = try container.customDecode(String.self, forKey: .revision) { Int($0) }
2121
}
2222

23-
init(layoutChunks: [FormLayoutChunk], revision: Int) {
23+
init(
24+
layoutChunks: [FormLayoutChunk],
25+
revision: Int
26+
) {
2427
self.layoutChunks = layoutChunks
2528
self.revision = revision
2629
}

Sources/KintoneAPI/Decodable/FetchRecordCommentsResponse.swift

-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,4 @@ public struct FetchRecordCommentsResponse: Decodable, Sendable, Equatable {
99
public var comments: [RecordComment.Read]
1010
public var older: Bool
1111
public var newer: Bool
12-
13-
init(comments: [RecordComment.Read], older: Bool, newer: Bool) {
14-
self.comments = comments
15-
self.older = older
16-
self.newer = newer
17-
}
1812
}

Sources/KintoneAPI/Decodable/FetchRecordsResponse.swift

-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,4 @@
88
public struct FetchRecordsResponse: Decodable, Sendable, Equatable {
99
public var records: [Record.Read]
1010
public var totalCount: Int?
11-
12-
init(records: [Record.Read], totalCount: Int?) {
13-
self.records = records
14-
self.totalCount = totalCount
15-
}
1611
}

Sources/KintoneAPI/Decodable/Field/Field.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ public struct Field: Decodable, Sendable, Equatable {
8787
}
8888
}
8989

90-
init(code: String, label: String, type: FieldType, attribute: FieldAttribute) {
90+
init(
91+
code: String,
92+
label: String,
93+
type: FieldType,
94+
attribute: FieldAttribute
95+
) {
9196
self.code = code
9297
self.label = label
9398
self.type = type

Sources/KintoneAPI/Decodable/Field/FieldAttribute/CalcAttribute.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ public struct CalcAttribute: Decodable, Sendable, Equatable {
3838
unitPosition = try container.decode(UnitPosition.self, forKey: .unitPosition)
3939
}
4040

41-
init(noLabel: Bool, required: Bool, expression: String, hideExpression: Bool, format: CalcFormat, displayScale: Int?, unit: String, unitPosition: UnitPosition) {
41+
init(
42+
noLabel: Bool,
43+
required: Bool,
44+
expression: String,
45+
hideExpression: Bool,
46+
format: CalcFormat,
47+
displayScale: Int?,
48+
unit: String,
49+
unitPosition: UnitPosition
50+
) {
4251
self.noLabel = noLabel
4352
self.required = required
4453
self.expression = expression

Sources/KintoneAPI/Decodable/Field/FieldAttribute/CategoryAttribute.swift

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77

88
public struct CategoryAttribute: Decodable, Sendable, Equatable {
99
public var enabled: Bool
10-
11-
init(enabled: Bool) {
12-
self.enabled = enabled
13-
}
1410
}

Sources/KintoneAPI/Decodable/Field/FieldAttribute/CheckBoxAttribute.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ public struct CheckBoxAttribute: Decodable, Sendable, Equatable {
2929
alignment = try container.decode(FieldOptionAlignment.self, forKey: .alignment)
3030
}
3131

32-
init(noLabel: Bool, required: Bool, options: [FieldOption], defaultValue: [String], alignment: FieldOptionAlignment) {
32+
init(
33+
noLabel: Bool,
34+
required: Bool,
35+
options: [FieldOption],
36+
defaultValue: [String],
37+
alignment: FieldOptionAlignment
38+
) {
3339
self.noLabel = noLabel
3440
self.required = required
3541
self.options = options

Sources/KintoneAPI/Decodable/Field/FieldAttribute/CreatedTimeAttribute.swift

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77

88
public struct CreatedTimeAttribute: Decodable, Sendable, Equatable {
99
public var noLabel: Bool
10-
11-
init(noLabel: Bool) {
12-
self.noLabel = noLabel
13-
}
1410
}

Sources/KintoneAPI/Decodable/Field/FieldAttribute/CreatorAttribute.swift

-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@
77

88
public struct CreatorAttribute: Decodable, Sendable, Equatable {
99
public var noLabel: Bool
10-
11-
init(noLabel: Bool) {
12-
self.noLabel = noLabel
13-
}
1410
}

Sources/KintoneAPI/Decodable/Field/FieldAttribute/DateAttribute.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ public struct DateAttribute: Decodable, Sendable, Equatable {
3232
defaultValue = DateFormatter.kintoneDate.date(from: _defaultValue) ?? Date.now
3333
}
3434

35-
init (noLabel: Bool, required: Bool, unique: Bool, defaultNowValue: Bool, defaultValue: Date) {
35+
init(
36+
noLabel: Bool,
37+
required: Bool,
38+
unique: Bool,
39+
defaultNowValue: Bool,
40+
defaultValue: Date
41+
) {
3642
self.noLabel = noLabel
3743
self.required = required
3844
self.unique = unique

Sources/KintoneAPI/Decodable/Field/FieldAttribute/DateTimeAttribute.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ public struct DateTimeAttribute: Decodable, Sendable, Equatable {
3232
defaultValue = DateFormatter.kintoneDateTime.date(from: _defaultValue.normalizedDateTime) ?? Date.now
3333
}
3434

35-
init(noLabel: Bool, required: Bool, unique: Bool, defaultNowValue: Bool, defaultValue: Date) {
35+
init(
36+
noLabel: Bool,
37+
required: Bool,
38+
unique: Bool,
39+
defaultNowValue: Bool,
40+
defaultValue: Date
41+
) {
3642
self.noLabel = noLabel
3743
self.required = required
3844
self.unique = unique

Sources/KintoneAPI/Decodable/Field/FieldAttribute/DropDownAttribute.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ public struct DropDownAttribute: Decodable, Sendable, Equatable {
2626
defaultValue = try container.decode(String.self, forKey: .defaultValue)
2727
}
2828

29-
init(noLabel: Bool, required: Bool, options: [FieldOption], defaultValue: String) {
29+
init(
30+
noLabel: Bool,
31+
required: Bool,
32+
options: [FieldOption],
33+
defaultValue: String
34+
) {
3035
self.noLabel = noLabel
3136
self.required = required
3237
self.options = options

Sources/KintoneAPI/Decodable/Field/FieldAttribute/FileAttribute.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public struct FileAttribute: Decodable, Sendable, Equatable {
2323
thumbnailSize = try container.customDecode(String.self, forKey: .thumbnailSize) { Int($0) }
2424
}
2525

26-
init(noLabel: Bool, required: Bool, thumbnailSize: Int) {
26+
init(
27+
noLabel: Bool,
28+
required: Bool,
29+
thumbnailSize: Int
30+
) {
2731
self.noLabel = noLabel
2832
self.required = required
2933
self.thumbnailSize = thumbnailSize

Sources/KintoneAPI/Decodable/Field/FieldAttribute/GroupAttribute.swift

-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,4 @@
88
public struct GroupAttribute: Decodable, Sendable, Equatable {
99
public var noLabel: Bool
1010
public var openGroup: Bool
11-
12-
init(noLabel: Bool, openGroup: Bool) {
13-
self.noLabel = noLabel
14-
self.openGroup = openGroup
15-
}
1611
}

Sources/KintoneAPI/Decodable/Field/FieldAttribute/GroupSelectAttribute.swift

-7
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,4 @@ public struct GroupSelectAttribute: Decodable, Sendable, Equatable {
1010
public var required: Bool
1111
public var entities: [Entity.Read]
1212
public var defaultValue: [Entity.Read]
13-
14-
init(noLabel: Bool, required: Bool, entities: [Entity.Read], defaultValue: [Entity.Read]) {
15-
self.noLabel = noLabel
16-
self.required = required
17-
self.entities = entities
18-
self.defaultValue = defaultValue
19-
}
2013
}

Sources/KintoneAPI/Decodable/Field/FieldAttribute/LinkAttribute.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ public struct LinkAttribute: Decodable, Sendable, Equatable {
3535
defaultValue = try container.decode(String.self, forKey: .defaultValue)
3636
}
3737

38-
init(noLabel: Bool, required: Bool, linkProtocol: LinkProtocol, minLength: Int?, maxLength: Int?, unique: Bool, defaultValue: String) {
38+
init(
39+
noLabel: Bool,
40+
required: Bool,
41+
linkProtocol: LinkProtocol,
42+
minLength: Int?,
43+
maxLength: Int?,
44+
unique: Bool,
45+
defaultValue: String
46+
) {
3947
self.noLabel = noLabel
4048
self.required = required
4149
self.linkProtocol = linkProtocol

0 commit comments

Comments
 (0)