Skip to content

Commit

Permalink
Merge pull request #11 from pawello2222/ios17-refactor
Browse files Browse the repository at this point in the history
[Refactor] Update project to iOS 17
  • Loading branch information
pawello2222 authored Oct 18, 2023
2 parents e50e31d + e7b6b1e commit eb3a5fa
Show file tree
Hide file tree
Showing 197 changed files with 8,184 additions and 3,691 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ on:
branches: [ main ]

env:
SCHEME: WidgetExamples
IOS_SDK: iphonesimulator
IOS_DESTINATION: "platform=iOS Simulator,name=iPhone 13 Pro,OS=latest"
SCHEME: "Widget Examples"
IOS_SDK: "iphonesimulator"
IOS_DESTINATION: "platform=iOS Simulator,name=Any iOS Simulator Device,OS=latest"

jobs:
lint:
Expand All @@ -21,13 +21,20 @@ jobs:
uses: norio-nomura/[email protected]

build:
runs-on: macos-latest
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Swift
uses: slashmo/[email protected]
with:
version: swift-5.9-DEVELOPMENT-SNAPSHOT-2023-07-04-a
- run: ls /Applications
- run: sudo xcode-select -s '/Applications/Xcode_15.0.app/Contents/Developer'
- name: Build
run: |
xcodebuild clean build \
-scheme "$SCHEME" \
-sdk "$IOS_SDK" \
-destination "$IOS_DESTINATION"
-destination "$IOS_DESTINATION" \
CODE_SIGNING_ALLOWED=NO
131 changes: 5 additions & 126 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,133 +1,12 @@
# Created by https://www.toptal.com/developers/gitignore/api/swift,xcode,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=swift,xcode,macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/
.build
.swiftpm/xcode/package.xcworkspace
.swiftpm/xcode/xcuserdata
Package.resolved

# CocoaPods
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

### Xcode ###
# Xcode
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore




## Gcc Patch
/*.gcno

### Xcode Patch ###
xcuserdata
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.toptal.com/developers/gitignore/api/swift,xcode,macos
Binary file added .resources/Assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions .resources/Assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 125 additions & 0 deletions .resources/Assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Assets/social.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
196 changes: 196 additions & 0 deletions .resources/Assets/social.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/AppGroupWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/CoreDataWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/CountdownWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/DeepLinkWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/DigitalClockWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/DynamicIntentWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/EnvironmentWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/IntentWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/InteractiveWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/LiveActivityWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/LockScreenWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/NetworkWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/SharedViewWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/SwiftDataWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Recordings/URLImageWidget.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Screenshots/AppGroupWidget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Screenshots/CoreDataWidget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Screenshots/CountdownWidget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Screenshots/DeepLinkWidget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .resources/Screenshots/DigitalClockWidget.png
Binary file added .resources/Screenshots/DynamicIntentWidget.png
Binary file added .resources/Screenshots/EnvironmentWidget.png
Binary file added .resources/Screenshots/IntentWidget.png
Binary file added .resources/Screenshots/InteractiveWidget.png
Binary file added .resources/Screenshots/LiveActivityWidget.png
Binary file added .resources/Screenshots/LockScreenWidget.png
Binary file added .resources/Screenshots/NetworkWidget.png
Binary file added .resources/Screenshots/SharedViewWidget.png
Binary file added .resources/Screenshots/SwiftDataWidget.png
Binary file added .resources/Screenshots/URLImageWidget.png
26 changes: 23 additions & 3 deletions App/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,30 @@ import SwiftUI
@main
struct WidgetExamplesApp: App {
var body: some Scene {
let moc = CoreDataStack.shared.managedObjectContext
return WindowGroup {
WindowGroup {
let persistenceController = PersistenceController.shared
ContentView()
.environment(\.managedObjectContext, moc)
.environment(\.managedObjectContext, persistenceController.managedObjectContext)
.modelContainer(for: Product.self)
}
}
}

// MARK: - Screenshots

extension WidgetExamplesApp {
@MainActor
private func createScreenshot() {
let view = SharedViewWidgetEntryView(entry: .placeholder)
.padding(15)
.frame(width: 150, height: 150)
.background(.white)
.clipShape(RoundedRectangle(cornerRadius: 20))
.padding(15)
.environment(\.locale, .init(identifier: "en_US"))
let renderer = ImageRenderer(content: view)
renderer.scale = 10
let filename = URL.documentsDirectory.appending(path: "SharedViewWidget.png")
try? renderer.uiImage?.pngData()?.write(to: filename)
}
}
140 changes: 11 additions & 129 deletions App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,143 +20,25 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import CoreData
import SwiftUI
import WidgetKit

struct ContentView: View {
@Environment(\.managedObjectContext) private var managedObjectContext
@FetchRequest(entity: Item.entity(), sortDescriptors: []) private var items: FetchedResults<Item>
@AppStorage(Key.luckyNumber.rawValue, store: .appGroup) private var luckyNumber = 0
@State private var contacts = Contact.getAll()
@State private var selection: AppScreen?

var body: some View {
List {
appGroupWidgetSection
coreDataWidgetSection
deepLinkWidgetSection
dynamicIntentWidgetSection
previewWidgetSection
NavigationSplitView(
columnVisibility: .constant(.doubleColumn),
preferredCompactColumn: .constant(.sidebar)
) {
AppSidebarList(selection: $selection)
} detail: {
AppDetailColumn(screen: selection)
}
.listStyle(InsetGroupedListStyle())
}
}

// MARK: - AppGroup Widget
// MARK: - Preview

extension ContentView {
private var appGroupWidgetSection: some View {
Section(header: Text("AppGroup Widget")) {
Text("Lucky number: \(luckyNumber)")
Button("Generate new lucky number") {
luckyNumber = Int.random(in: 1 ... 99)
WidgetCenter.shared.reloadTimelines(ofKind: WidgetKind.appGroup)
}
.buttonStyle(PlainButtonStyle())
.foregroundColor(.accentColor)
}
.onChange(of: luckyNumber) { _ in
let url = FileManager.appGroupContainerURL.appendingPathComponent(FileManager.luckyNumberFilename)
try? String(luckyNumber).write(to: url, atomically: false, encoding: .utf8)
}
}
}

// MARK: - CoreData Widget

extension ContentView {
private var coreDataWidgetSection: some View {
Section(header: Text("CoreData Widget")) {
Text("Items count: \(items.count)")
addNewItemsButton
deleteAllItemsButton
}
.onChange(of: luckyNumber) { _ in
let url = FileManager.appGroupContainerURL.appendingPathComponent(FileManager.luckyNumberFilename)
try? String(luckyNumber).write(to: url, atomically: false, encoding: .utf8)
}
}

private var addNewItemsButton: some View {
Button("Add new item") {
let context = CoreDataStack.shared.workingContext
let item = Item(context: context)
item.name = "test"
item.count = 1
CoreDataStack.shared.saveWorkingContext(context: context)
WidgetCenter.shared.reloadTimelines(ofKind: WidgetKind.coreData)
}
.buttonStyle(PlainButtonStyle())
.foregroundColor(.accentColor)
}

private var deleteAllItemsButton: some View {
Button("Delete all items") {
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Item")
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
do {
try CoreDataStack.shared.managedObjectContext.executeAndMergeChanges(deleteRequest)
} catch {
print(error.localizedDescription)
}
WidgetCenter.shared.reloadTimelines(ofKind: WidgetKind.coreData)
}
.buttonStyle(PlainButtonStyle())
.foregroundColor(.red)
}
}

// MARK: - DeepLink Widget

extension ContentView {
private var deepLinkWidgetSection: some View {
Section(header: Text("DeepLink Widget")) {
Text("")
.onOpenURL { url in
if url.scheme == "widget-DeepLinkWidget", url.host == "widgetFamily" {
let widgetFamily = url.lastPathComponent
print("Opened from widget of size: \(widgetFamily)")
}
}
}
}
}

// MARK: - Dynamic Intent Widget

extension ContentView {
private var dynamicIntentWidgetSection: some View {
Section(header: Text("Dynamic Intent Widget")) {
ForEach(contacts.indices, id: \.self) { index in
HStack {
TextField("", text: $contacts[index].name, onCommit: saveContacts)
DatePicker("", selection: $contacts[index].dateOfBirth, displayedComponents: .date)
.onChange(of: contacts[index].dateOfBirth) { _ in
saveContacts()
}
}
}
}
}

private func saveContacts() {
let key = UserDefaults.Keys.contacts.rawValue
UserDefaults.appGroup.setArray(contacts, forKey: key)
WidgetCenter.shared.reloadTimelines(ofKind: WidgetKind.dynamicIntent)
}
}

// MARK: - Preview Widget

extension ContentView {
private var previewWidgetSection: some View {
let entry = PreviewWidgetEntry(date: Date(), systemImageName: "star.fill")
return Section(header: Text("Preview Widget")) {
HStack {
PreviewWidgetEntryView(entry: entry)
.frame(width: 200, height: 200)
}
.frame(maxWidth: .infinity)
}
}
#Preview {
ContentView()
}
Loading

0 comments on commit eb3a5fa

Please sign in to comment.