diff --git a/EQ5cez8kvL-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.05.48.png b/EQ5cez8kvL-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.05.48.png new file mode 100644 index 0000000..e6cfad0 Binary files /dev/null and b/EQ5cez8kvL-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.05.48.png differ diff --git a/I_hqQzh0M-CleanShot_2024-10-09_at_14.15.26.jpg b/I_hqQzh0M-CleanShot_2024-10-09_at_14.15.26.jpg new file mode 100644 index 0000000..c1a0eae Binary files /dev/null and b/I_hqQzh0M-CleanShot_2024-10-09_at_14.15.26.jpg differ diff --git a/IiOTw8-4Z-CleanShot_2024-10-09_at_14.18.21.jpg b/IiOTw8-4Z-CleanShot_2024-10-09_at_14.18.21.jpg new file mode 100644 index 0000000..fd5e203 Binary files /dev/null and b/IiOTw8-4Z-CleanShot_2024-10-09_at_14.18.21.jpg differ diff --git a/JcAGbee2d-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.05.32.png b/JcAGbee2d-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.05.32.png new file mode 100644 index 0000000..8fb4cbb Binary files /dev/null and b/JcAGbee2d-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.05.32.png differ diff --git a/PgVXouKZx-CleanShot_2024-10-09_at_14.17.50.jpg b/PgVXouKZx-CleanShot_2024-10-09_at_14.17.50.jpg new file mode 100644 index 0000000..a80eece Binary files /dev/null and b/PgVXouKZx-CleanShot_2024-10-09_at_14.17.50.jpg differ diff --git a/Podfile b/Podfile new file mode 100644 index 0000000..d7a1046 --- /dev/null +++ b/Podfile @@ -0,0 +1,11 @@ +# Uncomment the next line to define a global platform for your project +platform :ios, '17.5' + +target 'RK-Setup-Cocoa' do + # Comment the next line if you don't want to use dynamic frameworks + use_frameworks! + + # Pods for RK-Setup-Cocoa + pod 'ResearchKit', '~> 2.2.16' + +end diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 0000000..64243fd --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,16 @@ +PODS: + - ResearchKit (2.2.16) + +DEPENDENCIES: + - ResearchKit (~> 2.2.16) + +SPEC REPOS: + trunk: + - ResearchKit + +SPEC CHECKSUMS: + ResearchKit: 4ce3751136fc82a02ac83f873b09b01b6974a761 + +PODFILE CHECKSUM: 8b097b6531f757d05b3aa8db7bb3d8658d9fe7b9 + +COCOAPODS: 1.15.2 diff --git a/RK-Setup-Cocoa.xcodeproj/project.pbxproj b/RK-Setup-Cocoa.xcodeproj/project.pbxproj index 5414698..cedf3e6 100644 --- a/RK-Setup-Cocoa.xcodeproj/project.pbxproj +++ b/RK-Setup-Cocoa.xcodeproj/project.pbxproj @@ -7,15 +7,18 @@ objects = { /* Begin PBXBuildFile section */ + 3C877D371ED5A51BEBB7E1E7 /* Pods_RK_Setup_Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 407D7A57E9878A5CD1C867BD /* Pods_RK_Setup_Cocoa.framework */; }; 7E6CBBD42CB64F8600D6576B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E6CBBD32CB64F8600D6576B /* AppDelegate.swift */; }; 7E6CBBD62CB64F8600D6576B /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E6CBBD52CB64F8600D6576B /* SceneDelegate.swift */; }; 7E6CBBD82CB64F8600D6576B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E6CBBD72CB64F8600D6576B /* ViewController.swift */; }; 7E6CBBDB2CB64F8600D6576B /* Base in Resources */ = {isa = PBXBuildFile; fileRef = 7E6CBBDA2CB64F8600D6576B /* Base */; }; 7E6CBBDD2CB64F8700D6576B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7E6CBBDC2CB64F8700D6576B /* Assets.xcassets */; }; 7E6CBBE02CB64F8700D6576B /* Base in Resources */ = {isa = PBXBuildFile; fileRef = 7E6CBBDF2CB64F8700D6576B /* Base */; }; + 7EF65FF62CB71EF000586508 /* SurveyTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EF65FF52CB71EF000586508 /* SurveyTask.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 407D7A57E9878A5CD1C867BD /* Pods_RK_Setup_Cocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RK_Setup_Cocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7E6CBBD02CB64F8600D6576B /* RK-Setup-Cocoa.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "RK-Setup-Cocoa.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 7E6CBBD32CB64F8600D6576B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7E6CBBD52CB64F8600D6576B /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -24,6 +27,11 @@ 7E6CBBDC2CB64F8700D6576B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 7E6CBBDF2CB64F8700D6576B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 7E6CBBE12CB64F8700D6576B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7EF65FF12CB71C7300586508 /* ResearchKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ResearchKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 7EF65FF52CB71EF000586508 /* SurveyTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyTask.swift; sourceTree = ""; }; + 7EF65FF72CB7213400586508 /* ResearchKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = ResearchKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + CE8208961E32537050788286 /* Pods-RK-Setup-Cocoa.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RK-Setup-Cocoa.release.xcconfig"; path = "Target Support Files/Pods-RK-Setup-Cocoa/Pods-RK-Setup-Cocoa.release.xcconfig"; sourceTree = ""; }; + F0F4B7D38A13A064677DF0E8 /* Pods-RK-Setup-Cocoa.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RK-Setup-Cocoa.debug.xcconfig"; path = "Target Support Files/Pods-RK-Setup-Cocoa/Pods-RK-Setup-Cocoa.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -31,17 +39,30 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 3C877D371ED5A51BEBB7E1E7 /* Pods_RK_Setup_Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 350602C639D1599CFF23B568 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 7EF65FF72CB7213400586508 /* ResearchKit.framework */, + 7EF65FF12CB71C7300586508 /* ResearchKit.framework */, + 407D7A57E9878A5CD1C867BD /* Pods_RK_Setup_Cocoa.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; 7E6CBBC72CB64F8600D6576B = { isa = PBXGroup; children = ( 7E6CBBD22CB64F8600D6576B /* RK-Setup-Cocoa */, 7E6CBBD12CB64F8600D6576B /* Products */, + F22CFCB5E0C96E3F8AA1D06B /* Pods */, + 350602C639D1599CFF23B568 /* Frameworks */, ); sourceTree = ""; }; @@ -63,10 +84,20 @@ 7E6CBBDC2CB64F8700D6576B /* Assets.xcassets */, 7E6CBBDE2CB64F8700D6576B /* LaunchScreen.storyboard */, 7E6CBBE12CB64F8700D6576B /* Info.plist */, + 7EF65FF52CB71EF000586508 /* SurveyTask.swift */, ); path = "RK-Setup-Cocoa"; sourceTree = ""; }; + F22CFCB5E0C96E3F8AA1D06B /* Pods */ = { + isa = PBXGroup; + children = ( + F0F4B7D38A13A064677DF0E8 /* Pods-RK-Setup-Cocoa.debug.xcconfig */, + CE8208961E32537050788286 /* Pods-RK-Setup-Cocoa.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -74,9 +105,11 @@ isa = PBXNativeTarget; buildConfigurationList = 7E6CBBE42CB64F8700D6576B /* Build configuration list for PBXNativeTarget "RK-Setup-Cocoa" */; buildPhases = ( + 8FFCF3B9EF19393867F186B3 /* [CP] Check Pods Manifest.lock */, 7E6CBBCC2CB64F8600D6576B /* Sources */, 7E6CBBCD2CB64F8600D6576B /* Frameworks */, 7E6CBBCE2CB64F8600D6576B /* Resources */, + 083961723BE5A342FD7248FB /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -133,11 +166,54 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 083961723BE5A342FD7248FB /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-RK-Setup-Cocoa/Pods-RK-Setup-Cocoa-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-RK-Setup-Cocoa/Pods-RK-Setup-Cocoa-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RK-Setup-Cocoa/Pods-RK-Setup-Cocoa-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 8FFCF3B9EF19393867F186B3 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-RK-Setup-Cocoa-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 7E6CBBCC2CB64F8600D6576B /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7EF65FF62CB71EF000586508 /* SurveyTask.swift in Sources */, 7E6CBBD82CB64F8600D6576B /* ViewController.swift in Sources */, 7E6CBBD42CB64F8600D6576B /* AppDelegate.swift in Sources */, 7E6CBBD62CB64F8600D6576B /* SceneDelegate.swift in Sources */, @@ -203,7 +279,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; - ENABLE_USER_SCRIPT_SANDBOXING = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu17; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -266,7 +342,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_USER_SCRIPT_SANDBOXING = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu17; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -287,6 +363,7 @@ }; 7E6CBBE52CB64F8700D6576B /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = F0F4B7D38A13A064677DF0E8 /* Pods-RK-Setup-Cocoa.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; @@ -315,6 +392,7 @@ }; 7E6CBBE62CB64F8700D6576B /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = CE8208961E32537050788286 /* Pods-RK-Setup-Cocoa.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; diff --git a/RK-Setup-Cocoa.xcodeproj/xcuserdata/gmarx.xcuserdatad/xcschemes/xcschememanagement.plist b/RK-Setup-Cocoa.xcodeproj/xcuserdata/gmarx.xcuserdatad/xcschemes/xcschememanagement.plist index 7016fb8..e6b0df6 100644 --- a/RK-Setup-Cocoa.xcodeproj/xcuserdata/gmarx.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/RK-Setup-Cocoa.xcodeproj/xcuserdata/gmarx.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ RK-Setup-Cocoa.xcscheme_^#shared#^_ orderHint - 0 + 2 diff --git a/RK-Setup-Cocoa.xcworkspace/contents.xcworkspacedata b/RK-Setup-Cocoa.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..7c1276b --- /dev/null +++ b/RK-Setup-Cocoa.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/RK-Setup-Cocoa.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/RK-Setup-Cocoa.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/RK-Setup-Cocoa.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/RK-Setup-Cocoa/Base.lproj/Main.storyboard b/RK-Setup-Cocoa/Base.lproj/Main.storyboard index 25a7638..17e5e85 100644 --- a/RK-Setup-Cocoa/Base.lproj/Main.storyboard +++ b/RK-Setup-Cocoa/Base.lproj/Main.storyboard @@ -1,24 +1,43 @@ - + + - + + - + - + - + + + + + + + + + + diff --git a/RK-Setup-Cocoa/SurveyTask.swift b/RK-Setup-Cocoa/SurveyTask.swift new file mode 100644 index 0000000..6c40c62 --- /dev/null +++ b/RK-Setup-Cocoa/SurveyTask.swift @@ -0,0 +1,40 @@ +// +// SurveyTask.swift +// RK-Setup-Cocoa +// +// Created by Gerardo Marx Chávez Campos on 09/10/24. +// + +import ResearchKit + +// Define a simple survey task +func createSurveyTask() -> ORKOrderedTask { + // Define a question step with a text answer format + let questionStepTitle = "How are you feeling today?" + let questionStep = ORKQuestionStep( + identifier: "QuestionStep", + title: questionStepTitle, + answer: ORKTextAnswerFormat(maximumLength: 100) + ) + questionStep.isOptional = false + + // Define another question as a scale (e.g., 1 to 10) + let scaleAnswerFormat = ORKAnswerFormat.scale( + withMaximumValue: 10, + minimumValue: 1, + defaultValue: 5, + step: 1, + vertical: false, + maximumValueDescription: "Excellent", + minimumValueDescription: "Terrible" + ) + let scaleStep = ORKQuestionStep( + identifier: "ScaleStep", + title: "Rate your overall well-being", + answer: scaleAnswerFormat + ) + scaleStep.isOptional = false + + // Create the ordered task with the steps + return ORKOrderedTask(identifier: "SurveyTask", steps: [questionStep, scaleStep]) +} diff --git a/RK-Setup-Cocoa/ViewController.swift b/RK-Setup-Cocoa/ViewController.swift index 4dc55c1..72b99d1 100644 --- a/RK-Setup-Cocoa/ViewController.swift +++ b/RK-Setup-Cocoa/ViewController.swift @@ -6,6 +6,7 @@ // import UIKit +import ResearchKit class ViewController: UIViewController { @@ -13,7 +14,34 @@ class ViewController: UIViewController { super.viewDidLoad() // Do any additional setup after loading the view. } + + @IBAction func startSurveyTapped(_ sender: UIButton) { + // Create a task view controller for the survey + let surveyTask = createSurveyTask() + let taskViewController = ORKTaskViewController(task: surveyTask, taskRun: nil) + taskViewController.delegate = self + present(taskViewController, animated: true, completion: nil) + } + } - + // Conform to the ORKTaskViewControllerDelegate protocol + extension ViewController: ORKTaskViewControllerDelegate { + func taskViewController( + _ taskViewController: ORKTaskViewController, + didFinishWith reason: ORKTaskViewControllerFinishReason, + error: Error? + ) { + // Handle the results of the survey here + if reason == .completed { + if let results = taskViewController.result.results { + for stepResult in results { + print("Step: \(stepResult.identifier), Results: \(stepResult)") + } + } + } + // Dismiss the task view controller + dismiss(animated: true, completion: nil) + } + } diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..ba1cadb --- /dev/null +++ b/Readme.md @@ -0,0 +1,251 @@ +# basic-setup-cocoapods + +# Readme +There’s another solution to integrate ResearchKit to your Xcode project, by using an iOS dependency manager called CocoaPods[^1]. The nice thing is that not only will it download and update the source code, but it will also configure the project for you. + +First, you need to install CocoaPods. It only takes one command for the Terminal when you use [Homebrew — The Missing Package Manager for macOS \(or Linux\)](https://brew.sh): + +```sh +$ brew install cocoapods +``` + +Then, the following steps will configure and isntall RK for your project. **The repository can be used as a base to start new project with ResearchKit previously added.** + + +## Step 1: Create a New Xcode Project + +- Open Xcode. +- Create a new project using “App” under iOS. +- Select the app template you want (e.g., “App”). +- Name your project, select a language (Swift), set the interface (Storyboard), and set the necessary configurations. +- Save it to a preferred location on your disk. + +## Step 2: Initialize CocoaPods in Your Project + +Open Terminal and navigate to your project’s directory: + +```sh +cd /path/to/your/project +``` + +Initialize CocoaPods for the project: + +```sh +pod init +``` + +## Step 3: Add ResearchKit to the Podfile + +- Open the generated Podfile using a text editor (Vim) or Xcode. +- Add the following line to include ResearchKit v3: + +``` +# Uncomment the next line to define a global platform for your project +# platform :ios, '9.0' + +target 'RK-Setup-Cocoa' do + # Comment the next line if you don't want to use dynamic frameworks + # use_frameworks! + + # Pods for RK-Setup-Cocoa + pod 'ResearchKit', '~> 2.2.16' + +end +``` + +- Save and close the Podfile. +**Note: the newest RK version (3.0.1) is not enable at cocoapods.** + +## Step 4: Install the Pod + +- Back in the terminal, run: + +```sh +pod install +``` + +- CocoaPods will download and set up ResearchKit and any dependencies it requires. +- Once the installation is complete, you will see a .xcworkspace file in your project folder. + +## Step 5: Open the Project Using the Workspace + +- From now on, always open your project using the .xcworkspace file: + +open YourProjectName.xcworkspace + +## Step 6: Import and Use ResearchKit in Your Project + +- Open the general settings in the main project: +![CleanShot 2024-10-09 at 14.15.26](I_hqQzh0M-CleanShot_2024-10-09_at_14.15.26.jpg) + +- Add the ResearchKit library: +![CleanShot 2024-10-09 at 14.17.35](s-BbnkzCn-CleanShot_2024-10-09_at_14.17.35.jpg) +![CleanShot 2024-10-09 at 14.17.50](PgVXouKZx-CleanShot_2024-10-09_at_14.17.50.jpg) +- Open your main `ViewController` or any other file where you want to use ResearchKit. +- Import ResearchKit at the top of the file: + +```swift +import ResearchKit +``` + +![CleanShot 2024-10-09 at 14.18.21](IiOTw8-4Z-CleanShot_2024-10-09_at_14.18.21.jpg) + +- Now you can start using ResearchKit to build surveys, consent forms, tasks, and more. + +# Example: Basic Survey Task +## Project Structure + +We’ll create a new file called `SurveyTask.swift` that contains the survey logic. The ViewController will be responsible for presenting the survey task but will keep the survey creation logic separate. + +## Step 1: Create SurveyTask.swift + + 1. In Xcode, create a new Swift file named `SurveyTask.swift`. + 2. Add the following code to SurveyTask.swift: + +```swift +import ResearchKit + +// Define a simple survey task +func createSurveyTask() -> ORKOrderedTask { + // Define a question step with a text answer format + let questionStepTitle = "How are you feeling today?" + let questionStep = ORKQuestionStep( + identifier: "QuestionStep", + title: questionStepTitle, + answer: ORKTextAnswerFormat(maximumLength: 100) + ) + questionStep.isOptional = false + + // Define another question as a scale (e.g., 1 to 10) + let scaleAnswerFormat = ORKAnswerFormat.scale( + withMaximumValue: 10, + minimumValue: 1, + defaultValue: 5, + step: 1, + vertical: false, + maximumValueDescription: "Excellent", + minimumValueDescription: "Terrible" + ) + let scaleStep = ORKQuestionStep( + identifier: "ScaleStep", + title: "Rate your overall well-being", + answer: scaleAnswerFormat + ) + scaleStep.isOptional = false + + // Create the ordered task with the steps + return ORKOrderedTask(identifier: "SurveyTask", steps: [questionStep, scaleStep]) +} +``` + + +This file defines a function `createSurveyTask()` that returns a simple survey with two questions: one text-based and one scale-based. + +## Step 2: Update ViewController.swift + +1. In `ViewController.swift`, add the following code: + +```swift +import UIKit +import ResearchKit + +class ViewController: UIViewController { + + @IBAction func startSurveyTapped(_ sender: UIButton) { + // Create a task view controller for the survey + let surveyTask = createSurveyTask() + let taskViewController = ORKTaskViewController(task: surveyTask, taskRun: nil) + taskViewController.delegate = self + present(taskViewController, animated: true, completion: nil) + } +} + +// Conform to the ORKTaskViewControllerDelegate protocol +extension ViewController: ORKTaskViewControllerDelegate { + func taskViewController( + _ taskViewController: ORKTaskViewController, + didFinishWith reason: ORKTaskViewControllerFinishReason, + error: Error? + ) { + // Handle the results of the survey here + if reason == .completed { + if let results = taskViewController.result.results { + for stepResult in results { + print("Step: \(stepResult.identifier), Results: \(stepResult)") + } + } + } + // Dismiss the task view controller + dismiss(animated: true, completion: nil) + } +} +``` + +In this code: + +- The `startSurveyTapped` function is called when a button is tapped. +- It creates a survey using the `createSurveyTask()` function from `SurveyTask.swift` and presents the `ORKTaskViewController`. +- The `ViewController` conforms to the `ORKTaskViewControllerDelegate` to handle the completion of the survey. + +## Step 3: Hook Up the Button in the Storyboard + +- Open the main storyboard in Xcode. + +- Add a button to your ViewController scene: +- +![CleanShot 2024-10-09 at 22.01.52@2x](acJfu3Mzz-CleanShot_2024-10-09_at_22.01.52@2x.jpg) + +- Control-drag from the button to the ViewController code and create an @IBAction named startSurveyTapped. +![CleanShot 2024-10-09 at 22.24.18@2x](lt_VdI62G-CleanShot_2024-10-09_at_22.24.18@2x.jpg) + +- Build and run the app on a simulator or a real device. + + +![Simulator Screenshot - iPhone 15 Pro - 2024-10-09 at 22.05.32](JcAGbee2d-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.05.32.png) + +![Simulator Screenshot - iPhone 15 Pro - 2024-10-09 at 22.05.48](EQ5cez8kvL-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.05.48.png) +![Simulator Screenshot - iPhone 15 Pro - 2024-10-09 at 22.06.09](ZltrCxNZTu-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.06.09.png) + + + + + +# Useful commands of cocoapods + +```sh +brew upgrade cocoapods +pod repo update +``` + +```sh +pod search ResearchKit +-> ResearchKit (2.2.16) + ResearchKit is an open source software framework that makes it easy to create apps for medical research or for other research projects. + pod 'ResearchKit', '~> 2.2.16' + - Homepage: https://www.github.com/ResearchKit/ResearchKit + - Source: https://github.com/ResearchKit/ResearchKit.git + - Versions: 2.2.16, 2.2.15, 2.1.0, 2.0.0, 1.5.2, 1.5.0, 1.4.1, 1.3.1, 1.3.0, 1.2.1, 1.2, 1.1.2, 1.0.0 [trunk repo] + +-> FYAMResearchKit (3.0.0) + ResearchKit is an open source software framework that makes it easy to create apps for medical research or for other research projects. + pod 'FYAMResearchKit', '~> 3.0.0' + - Homepage: https://github.com/balzo-tech/ResearchKit + - Source: https://github.com/balzo-tech/ResearchKit + - Versions: 3.0.0, 2.3.0, 2.2.0, 2.1.3 [trunk repo] + +-> KinveyResearchKit (0.0.3) + ResearchKit wrapper for Kinvey + pod 'KinveyResearchKit', '~> 0.0.3' + - Homepage: https://github.com/Kinvey/kinvey-researchkit + - Source: https://github.com/Kinvey/kinvey-researchkit.git + - Versions: 0.0.3, 0.0.2, 0.0.1 [trunk repo] + +-> CGSearchKit (0.0.1) + A short description of CGSearchKit. + pod 'CGSearchKit', '~> 0.0.1' + - Homepage: https://gitee.com/chen_guo/CGSearchKit.git + - Source: https://gitee.com/chen_guo/CGSearchKit.git + - Versions: 0.0.1 [trunk repo] +``` + +[^1]: [shazino - Advanced ResearchKit project setup](https://blog.shazino.com/articles/dev/researchkit-advanced-setup/) \ No newline at end of file diff --git a/ZltrCxNZTu-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.06.09.png b/ZltrCxNZTu-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.06.09.png new file mode 100644 index 0000000..8b70f47 Binary files /dev/null and b/ZltrCxNZTu-Simulator_Screenshot_-_iPhone_15_Pro_-_2024-10-09_at_22.06.09.png differ diff --git a/acJfu3Mzz-CleanShot_2024-10-09_at_22.01.52@2x.jpg b/acJfu3Mzz-CleanShot_2024-10-09_at_22.01.52@2x.jpg new file mode 100644 index 0000000..5ee736c Binary files /dev/null and b/acJfu3Mzz-CleanShot_2024-10-09_at_22.01.52@2x.jpg differ diff --git a/lt_VdI62G-CleanShot_2024-10-09_at_22.24.18@2x.jpg b/lt_VdI62G-CleanShot_2024-10-09_at_22.24.18@2x.jpg new file mode 100644 index 0000000..f6c118d Binary files /dev/null and b/lt_VdI62G-CleanShot_2024-10-09_at_22.24.18@2x.jpg differ diff --git a/s-BbnkzCn-CleanShot_2024-10-09_at_14.17.35.jpg b/s-BbnkzCn-CleanShot_2024-10-09_at_14.17.35.jpg new file mode 100644 index 0000000..723f597 Binary files /dev/null and b/s-BbnkzCn-CleanShot_2024-10-09_at_14.17.35.jpg differ