-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lazar Otasevic
committed
Sep 7, 2024
1 parent
4d8dd8e
commit 9cc238a
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import requests | ||
import json | ||
|
||
url = 'https://developer.apple.com/tutorials/data/documentation/swiftui/gesture.json' | ||
response = requests.get(url) | ||
doc = response.json() | ||
identifiers = doc['relationshipsSections'][0]['identifiers'] | ||
gestures = [x.split("/")[-1] for x in identifiers] | ||
|
||
with open('parsed.json', 'r') as file: | ||
structs = json.load(file) | ||
|
||
preferedTypes = { | ||
'View' : 'Never', | ||
'Shape': 'Circle', | ||
'InsettableShape': 'Circle', | ||
'Hashable': 'Int', | ||
'RandomAccessCollection': 'Array<Never>', | ||
'Publisher': 'AnyPublisher<Void,Never>', | ||
'TimelineSchedule': 'AnimationTimelineSchedule', | ||
} | ||
|
||
output = [] | ||
for struct in structs: | ||
name = struct['name'] | ||
|
||
if not name in gestures: | ||
continue | ||
|
||
lines = struct.get('availabilities', []) | ||
generics = struct.get('generics') | ||
if generics is None: | ||
t = f'typealias _{name} = SameTypeElement<{name}>' | ||
else: | ||
conditions = struct.get('conditions', {}) | ||
arr = [conditions.get(gen, ['Never'])[-1] for gen in generics] | ||
arr = [preferedTypes.get(x, 'Never') for x in arr] | ||
gen = ",".join(arr) | ||
t = f"typealias _{name} = SameBaseElement<{name}<{gen}>>" | ||
|
||
lines.append(t) | ||
|
||
output.append(lines) | ||
|
||
strings = ["\n".join(lines) for lines in output] | ||
|
||
content = "\n\n".join(strings) | ||
|
||
with open('gesture.swift', 'w', encoding='utf-8') as f: | ||
f.write(content) | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
typealias _AnyGesture = SameBaseElement<AnyGesture<Never>> | ||
|
||
@available(iOS 13.0, macOS 10.15, watchOS 6.0, *) | ||
@available(tvOS, unavailable) | ||
typealias _DragGesture = SameTypeElement<DragGesture> | ||
|
||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
typealias _ExclusiveGesture = SameBaseElement<ExclusiveGesture<Never,Never>> | ||
|
||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
typealias _GestureStateGesture = SameBaseElement<GestureStateGesture<Never,Never>> | ||
|
||
@available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 14.0, *) | ||
typealias _LongPressGesture = SameTypeElement<LongPressGesture> | ||
|
||
@available(iOS, introduced: 13.0, deprecated: 100000.0, renamed: "MagnifyGesture") | ||
@available(macOS, introduced: 10.15, deprecated: 100000.0, renamed: "MagnifyGesture") | ||
@available(watchOS, unavailable) | ||
@available(tvOS, unavailable) | ||
@available(visionOS, introduced: 1.0, deprecated: 100000.0, renamed: "MagnifyGesture") | ||
typealias _MagnificationGesture = SameTypeElement<MagnificationGesture> | ||
|
||
@available(iOS 17.0, macOS 14.0, *) | ||
@available(watchOS, unavailable) | ||
@available(tvOS, unavailable) | ||
typealias _MagnifyGesture = SameTypeElement<MagnifyGesture> | ||
|
||
@available(iOS 17.0, macOS 14.0, *) | ||
@available(watchOS, unavailable) | ||
@available(tvOS, unavailable) | ||
typealias _RotateGesture = SameTypeElement<RotateGesture> | ||
|
||
@available(iOS, introduced: 13.0, deprecated: 100000.0, renamed: "RotateGesture") | ||
@available(macOS, introduced: 10.15, deprecated: 100000.0, renamed: "RotateGesture") | ||
@available(tvOS, unavailable) | ||
@available(watchOS, unavailable) | ||
@available(visionOS, introduced: 1.0, deprecated: 100000.0, renamed: "RotateGesture") | ||
typealias _RotationGesture = SameTypeElement<RotationGesture> | ||
|
||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
typealias _SequenceGesture = SameBaseElement<SequenceGesture<Never,Never>> | ||
|
||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
typealias _SimultaneousGesture = SameBaseElement<SimultaneousGesture<Never,Never>> | ||
|
||
@available(visionOS 1.0, iOS 18.0, macOS 15.0, watchOS 11.0, *) | ||
@available(tvOS, unavailable) | ||
typealias _SpatialEventGesture = SameTypeElement<SpatialEventGesture> | ||
|
||
@available(iOS 16.0, macOS 13.0, watchOS 9.0, visionOS 1.0, *) | ||
@available(tvOS, unavailable) | ||
typealias _SpatialTapGesture = SameTypeElement<SpatialTapGesture> | ||
|
||
@available(iOS 13.0, macOS 10.15, tvOS 16.0, watchOS 6.0, *) | ||
typealias _TapGesture = SameTypeElement<TapGesture> | ||
|
||
@available(macOS 15.0, *) | ||
@available(iOS, unavailable) | ||
@available(watchOS, unavailable) | ||
@available(tvOS, unavailable) | ||
@available(visionOS, unavailable) | ||
typealias _WindowDragGesture = SameTypeElement<WindowDragGesture> |
File renamed without changes.