https://github.com/alemohamad/swift-playground-app-structure
Package App Structure in Swift Playgrounds
https://github.com/alemohamad/swift-playground-app-structure
ipados macos package playgrounds swift xcode
Last synced: 3 months ago
JSON representation
Package App Structure in Swift Playgrounds
- Host: GitHub
- URL: https://github.com/alemohamad/swift-playground-app-structure
- Owner: alemohamad
- Created: 2023-12-01T17:08:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-10T16:03:04.000Z (about 2 years ago)
- Last Synced: 2025-06-19T20:39:13.937Z (about 1 year ago)
- Topics: ipados, macos, package, playgrounds, swift, xcode
- Language: Swift
- Homepage:
- Size: 969 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.es.md
Awesome Lists containing this project
README
# Echando un Vistazo al Interior de una App Playground en Swift Playgrounds
¡Hola!
¿Alguna vez te has preguntado qué hay dentro de una App Playground en **Swift Playgrounds**? Bueno, tengo algo genial para ti. En este [video](https://youtu.be/Q7f3Y34TvbI), te muestro cómo configurar todo desde cero: desde el archivo `Package.swift` hasta agregar tus propios módulos, e incluso cómo hacer pruebas unitarias (que, por ahora, solo funcionan en Xcode, ¡pero crucemos los dedos para Swift Playgrounds también! 🤞).
En este repositorio, expuse todo lo que necesitas saber sobre `Package.swift` y muchas otras cosas. También hay un proyecto de muestra y algunos enlaces que podrían resultar realmente útiles.
¡Espero que te ayude y te diviertas tanto como yo!
## Versión final de Package.swift
```swift
// swift-tools-version: 5.9
// WARNING:
// This file is automatically generated.
// Do not edit it by hand because the contents will be replaced.
import PackageDescription
import AppleProductTypes
let package = Package(
name: "YouTube",
defaultLocalization: "en",
platforms: [
.iOS("17.0")
],
products: [
.library(
name: "ExampleKit",
targets: ["ExampleKit"]
),
.iOSApplication(
name: "YouTube",
targets: ["AppModule"],
bundleIdentifier: "com.alemohamad.YouTube",
teamIdentifier: "YOUR-TEAM-IDENTIFIER",
displayVersion: "1.0",
bundleVersion: "1",
appIcon: .asset("AppIcon"),
accentColor: .asset("AccentColor"),
supportedDeviceFamilies: [
.pad,
.phone
],
supportedInterfaceOrientations: [
.portrait,
.landscapeRight,
.landscapeLeft,
.portraitUpsideDown(.when(deviceFamilies: [.pad]))
],
appCategory: .education,
additionalInfoPlistContentFilePath: "AppInfo.plist"
)
],
targets: [
.executableTarget(
name: "AppModule",
dependencies: [
"ExampleKit"
]
),
.target(
name: "ExampleKit"
),
.testTarget(
name: "AppModuleTest",
dependencies: [
"ExampleKit"
]
)
]
)
```
**Note Importante:** Después de completar el proyecto, descubrí un problema crítico: si `AppModule` incluye la carpeta `Assets.xcassets`, hace que `testTarget` falle, rompiendo todo el proyecto en Xcode. Para resolver esto y garantizar que el proyecto funcione correctamente, tuve que modificar la dependencia de `testTarget` de `AppModule` a `ExampleKit`. Y funciona porque `ExampleKit` contiene la lógica que pretendo probar. Todo lo demás queda como se demuestra en el vídeo.
## Swift Package Manager
- [Swift.org](https://docs.swift.org/package-manager/)
- [Apple Developer](https://developer.apple.com/documentation/packagedescription)
- [GitHub](https://github.com/apple/swift-package-manager/)
## [Platform](https://developer.apple.com/documentation/packagedescription/platform)
### [SupportedPlatform](https://developer.apple.com/documentation/packagedescription/supportedplatform)
```swift
platforms: [
.iOS("17.0"),
.macOS("14.0"),
.watchOS("10.0"),
.tvOS("17.0"),
.visionOS("1.0"),
.macCatalyst("17.0"),
.driverKit("23.0"),
.linux(""),
.openbsd(""),
.wasi(""), // WebAssembly System Interafce
.android(""),
.windows(""),
.custom("")
],
```
### [iOSVersion](https://developer.apple.com/documentation/packagedescription/supportedplatform/iosversion)
```swift
.iOS("17.0")
.iOS(.v17)
.iOS("16.1")
.iOS(.v16_1) // la constante no funciona en versiones menores, debes usar solo la principal
```
```swift
// Swift Playgrounds soporta estas versiones de iOS:
// 17.0
// 16.0, 16.1, 16.2, 16.3, 16.4, 16.5, 16.6
// 15.2, 15.3, 15.4, 15.5, 15.6
```
## [Product](https://developer.apple.com/documentation/packagedescription/product)
```swift
products: [
.library(name: "", type: .dynamic, targets: []), // .static
.executable(name: "", targets: []),
.plugin(name: "", targets: []),
.iOSApplication(name: "", targets: []) // sólo en el framework AppleProductTypes
],
```
### [UIUserInterfaceIdiom](https://developer.apple.com/documentation/uikit/uiuserinterfaceidiom)
```swift
supportedDeviceFamilies: [
.phone,
.pad,
.tv, // ?
.carPlay, // ?
.mac, // ?
.vision, // ?
.unspecified // ?
]
```
### [UIDeviceOrientation](https://developer.apple.com/documentation/uikit/uideviceorientation)
```swift
supportedInterfaceOrientations: [
.portrait,
.portraitUpsideDown,
.landscapeRight,
.landscapeLeft,
.faceUp,
.faceDown,
.unknown
]
```
### App Icon
```swift
appIcon: .placeholder(icon: .coffee),
appIcon: .asset("AppIcon"),
// 54 iconos:
// .bird .bunny .cat .dog .butterfly
// .flower .leaf .carrot .bowl .coffee
// .sandwich .twoPeople .running .calendar .camera
// .clock .gamepad .map .movieReel .palette
// .pencil .openBook .calculator .images .mic
// .box .coins .weights .paper .tv
// .binoculars .bandage .magicWand .gift .rocket
// .earth .beachball .barChart .heart .note
// .smiley .star .location .lightningBolt .checkmark
// .chatMessage .sparkle .bicycle .boat .car
// .plane .moon .sun .cloud
```
### Accent Color
```swift
accentColor: .presetColor(.orange),
accentColor: .asset("AccentColor"),
// 12 colores:
// .red .orange .yellow
// .green .mint .teal
// .cyan .blue .indigo
// .purple .pink .brown
```
### App Category
```swift
.books // Books
.business // Business
.developerTools // Developer Tools
.education // Education
.entertainment // Entertainment
.finance // Finance
.food-and-drink // Food & Drink
.games // Games
.actionGames // Games - Action Games
.adventureGames // Games - Adventure Games
.boardGames // Games - Board Games
.cardGames // Games - Card Games
.casinoGames // Games - Casino Games
.arcadeGames // Games - Casual Games
.familyGames // Games - Family Games
.kidsGames // Games - Kids Games
.musicGames // Games - Music Games
.puzzleGames // Games - Puzzle Games
.racingGames // Games - Racing Games
.rolePlayingGames // Games - Role Playing Games
.simulationGames // Games - Simulation Games
.sportsGames // Games - Sports Games
.strategyGames // Games - Strategy Games
.triviaGames // Games - Trivia Games
.wordGames // Games - Word Games
.graphicsDesign // Graphics & Design
.healthcareFitness // Health & Fitness
.lifestyle // Lifestyle
.magazines-and-newspapers // Magazines & Newspapers
.medical // Medical
.music // Music
.navigation // Navigation
.news // News
.photography // Photography
.productivity // Productivity
.reference // Reference
.shopping // Shopping
.socialNetworking // Social Networking
.sports // Sports
.travel // Travel
.utilities // Utilities
.video // Video
.weather // Weather
```
## [Target](https://developer.apple.com/documentation/packagedescription/target)
```swift
.target(name: "")
.executableTarget(name: "")
.testTarget(name: "")
.systemLibrary(name: "")
.binaryTarget(name: "", path: "")
.plugin(name: "")
```
## Reference links
- ["Swift Playgrounds App Projects" by Aaron Sky (Nov 6, 2021)](https://skyaaron.com/posts/swiftpm-app-projects/)
- ["A document-based app in Swift Playgrounds for iPad" by Guilherme Rambo (Dec 28, 2021)](https://rambo.codes/posts/2021-12-28-a-document-based-app-in-swift-playgrounds-for-ipad)
- ["Lessons from Developing an App on the iPad in Swift Playgrounds from Start to Finish (Including Publishing on the App Store)" by Matt Waller (Jan 4, 2022)](https://www.cephalopod.studio/blog/lessons-from-developing-an-app-on-the-ipad-from-start-to-finish-on-the-app-store)
- ["Changing the Thumbnail of an App in Swift Playgrounds" by Tiago Gomes Pereira (Apr 7, 2022)](https://www.createwithswift.com/changing-the-thumbnail-of-an-app-in-swift-playgrounds/)