Project Ok

main
Gerardo Marx 2 months ago
parent 615d30eefa
commit 69eb108dab

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

@ -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

@ -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

@ -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 = "<group>"; };
7E6CBBD52CB64F8600D6576B /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@ -24,6 +27,11 @@
7E6CBBDC2CB64F8700D6576B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7E6CBBDF2CB64F8700D6576B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
7E6CBBE12CB64F8700D6576B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
/* 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 = "<group>";
};
7E6CBBC72CB64F8600D6576B = {
isa = PBXGroup;
children = (
7E6CBBD22CB64F8600D6576B /* RK-Setup-Cocoa */,
7E6CBBD12CB64F8600D6576B /* Products */,
F22CFCB5E0C96E3F8AA1D06B /* Pods */,
350602C639D1599CFF23B568 /* Frameworks */,
);
sourceTree = "<group>";
};
@ -63,10 +84,20 @@
7E6CBBDC2CB64F8700D6576B /* Assets.xcassets */,
7E6CBBDE2CB64F8700D6576B /* LaunchScreen.storyboard */,
7E6CBBE12CB64F8700D6576B /* Info.plist */,
7EF65FF52CB71EF000586508 /* SurveyTask.swift */,
);
path = "RK-Setup-Cocoa";
sourceTree = "<group>";
};
F22CFCB5E0C96E3F8AA1D06B /* Pods */ = {
isa = PBXGroup;
children = (
F0F4B7D38A13A064677DF0E8 /* Pods-RK-Setup-Cocoa.debug.xcconfig */,
CE8208961E32537050788286 /* Pods-RK-Setup-Cocoa.release.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
};
/* 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;

@ -7,7 +7,7 @@
<key>RK-Setup-Cocoa.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>2</integer>
</dict>
</dict>
</dict>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:RK-Setup-Cocoa.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

@ -1,24 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="RK_Setup_Cocoa" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JyM-D2-S0W">
<rect key="frame" x="159" y="409" width="75" height="35"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Button"/>
<connections>
<action selector="startSurveyTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="YBX-WC-iRv"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="132" y="-27"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>

@ -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])
}

@ -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)
}
}

@ -0,0 +1,251 @@
# basic-setup-cocoapods
# Readme
Theres 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 projects 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
Well 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/)

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Loading…
Cancel
Save