Skip to content

Instantly share code, notes, and snippets.

View RNHTTR's full-sized avatar

Ryan Hatter RNHTTR

  • Astronomer
View GitHub Profile
@RNHTTR
RNHTTR / ARBasicObject.swift
Last active November 14, 2018 02:40
Create a basic AR object using ARKit and SCNKit
// Creating a simple Augmented Reality object with ARKit and SceneKit is surprisingly easy! But before you get started, you
// need to add a key-value pair to your application's Info.plist (Information Property List) file. Add the key "Privacy -
// Camera Usage Description" with the corresponding value "This application will use your camera for Augmented Reality", or
// some similarly descriptive note.
// Let's get started!
// You'll need to import SceneKit to create your object and ARKit to place it in your augmented reality space.
import UIKit
import SceneKit
@RNHTTR
RNHTTR / ARTextViewController.swift
Last active September 22, 2017 13:37
Create a simple 3D text object in augmented reality
// Creating a 3D text object with ARKit isn't overwhelming. It might not be immediately obvious, but these objects could
// be quite valuable moving forward. Imagine dropping a 3D advertisement in someone's augmented reality universe...
// We'll get started in a sec, but first you need to add a key-value pair to your application's Info.plist (Information
// Property List) file. Add the key "Privacy - Camera Usage Description" with the corresponding value "This application
// will use your camera for Augmented Reality", or some similarly descriptive note.
// Let's get started!
// You'll need to import SceneKit to create your object and ARKit to place it in your augmented reality space.
@RNHTTR
RNHTTR / ARMultipleObjectsViewController.swift
Last active September 22, 2017 13:40
Add a second object (a sphere) to your Augmented Reality space
// Adding a second object to your Augmented Reality space is not much different from adding the first, so we will change
// things up here a bit. Here we will create a sphere in addition to a box and we will give our objects some style.
// If you haven't already, you need to add a key-value pair to your application's Info.plist (Information Property List) file.
// Add the key "Privacy - Camera Usage Description" with the corresponding value "This application will use your camera for
// Augmented Reality", or some similarly descriptive note.
// Let's get started!
// You'll need to import SceneKit to create and edit your objects and ARKit to place it in your augmented reality space.
@RNHTTR
RNHTTR / ARTouchGestureInteractionViewController.swift
Created September 22, 2017 14:09
Interacting with Augmented Reality objects is not as hard as you might think
// Using touch gestures to interact with your Augmented Reality objects actually doesn't involve more ARKit code! Rather,
// you'll have to implement some new SCNKit code and play with a UITapGestureRecognizer from good ol' UIKit. Here we will
// create a Super Mario box, and it will pop up as if you were Mario jumping underneath it!
// If you're jumping straight into this view controller, you might need to update your info.plist (Information Property
// List) file first. Add the key "Privacy - Camera Usage Description" with the corresponding value "This application will
// use your camera for Augmented Reality", or some similarly descriptive note.
// Let's get started!
@RNHTTR
RNHTTR / heightForRowAtIndexPath.swift
Created September 23, 2017 19:38
Example of how to use tableView(_:heightForRowAt:) to adjust the height of a UITableViewCell
// The table views in this app actually don't make use of tableView(_:heightForRowAt:). These table views set the table views'
// rowHeight and estimatedRowHeight properties to UITableViewAutomaticDimension and 110, respectively, and they make use
// of a series of constraints to automatically set each cells' row height.
// Use tableView(_:heightForRowAt:) to set the height for specific table view cells.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// Set the row height for the first (zeroth) cell in all section(s) to 100, and set all other cells to 50.
// You can also set the row height for all cells in a section by accessing indexPath.section.
if indexPath.row == 0 {
@RNHTTR
RNHTTR / didSelectRowAtIndexPath.swift
Created September 23, 2017 20:01
An example of how to use tableView(_:didSelectRowAt:) to manage what happens when users select a UITableViewCell
// Use tableView(_:didSelectRowAt:) to manage what happens when a user selects a UITableViewCell.
// This example exhibits how this app makes use of this method.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Determine what to do when a cell in a particular section is selected.
switch indexPath.section {
case 0:
// If the cell in the first section is selected, this will trigger the segue with the "toHeightForRowAt" identifier
self.performSegue(withIdentifier: "toHeightForRowAt", sender: nil)
@RNHTTR
RNHTTR / editActionsForRowAt.swift
Created September 23, 2017 20:14
Use tableView(_:editActionsForRowAt:) to implement swipe actions for a UITableView's cells.
// Use tableView(_:editActionsForRowAt:) to implement swipe actions for a UITableView's cells.
// This example exhibits how this app makes use of this method.
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
// Get the title of each section to notify the user that a cell in a particular section was swiped.
let sectionHeaderView = tableView.headerView(forSection: indexPath.section)
let sectionTitle = sectionHeaderView?.textLabel?.text
// Create an action. Create custom actions in the UITableViewRowAction's closure.
@RNHTTR
RNHTTR / numberOfRowsInSection.swift
Created September 25, 2017 02:30
Determine the number of rows in each of a UITableView's sections
// Use tableView(_:numberOfRowsInSection:) to determine the number of rows each section of a UITableView should display.
// This example exhibits how this app makes use of this method.
// Create some sort of data source. This is often an array or, in this case, a dictionary.
var dataSource: [String: String] {
return ["cellForRowAt: indexPath": "Update cell information based on the data source\nReturns a UITableViewCell.",
"numberOfRowsInSection: Int": "Determine the number of rows needed for each section of the tableView\nReturns an Int",
"titleForHeaderInSection: Int": "Set the title for a particular section of your tableView\nReturns a String"]
}
@RNHTTR
RNHTTR / titleForHeaderInSection.swift
Created September 25, 2017 02:44
Determine the title for each section in a UITableView.
// Use tableView(_:titleForHeaderInSection:) to set the title for each section in a table view.
// This example exhibits two instances of this method used in this app.
// This demonstrates the use of this method in this app's UITableViewDataSource view controller.
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0:
return "Configuring a Table View"
default:
print("out of index")
@RNHTTR
RNHTTR / cellForRowAt.swift
Created September 25, 2017 02:53
Customize the cells in a UITableView
// Use tableView(_:cellForRowAt:) to customize the cells in a table view.
// This example demonstrates an instance of how one of this app's table views uses this method.
// Create some sort of data source. This is often an array or, in this case, a dictionary.
var dataSource: [String: String] {
return ["cellForRowAt: indexPath": "Update cell information based on the data source\nReturns a UITableViewCell.",
"numberOfRowsInSection: Int": "Determine the number of rows needed for each section of the tableView\nReturns an Int",
"titleForHeaderInSection: Int": "Set the title for a particular section of your tableView\nReturns a String"]
}