This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Moving keyboard for item | |
// | |
// Note: Comments with this label are to explain semantics of iOS | |
// Do not use comments like these in your projects | |
import UIKit | |
class ViewController: UIViewController, UITextFieldDelegate { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Moving keyboard for item | |
// | |
// Note: Comments with this label are to explain semantics of iOS | |
// Do not use comments like these in your projects | |
import UIKit | |
class ViewController: UIViewController, UITextFieldDelegate { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Read the classRecord instance from the bundle plist Class489.plist */ | |
// url of resource file | |
// Note: Assumes you have added a Class489.plist dictionary | |
guard let classURL = Bundle.main.url(forResource: "class489", withExtension:"plist") else { | |
print("Error: Unable to form path") | |
return | |
} | |
// data in resource file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Read the classRecord instance from the bundle plist Class489.plist */ | |
// url of resource file | |
guard let classURL = URL(string: "https://gist.githubusercontent.com/mlcollard/7a50ac639316ff3c375e835f297ccf71/raw/199faedf8e2d3b69fa98d0db31602e333d844225/class489.plist") else { | |
print("Error: Unable to form path") | |
return | |
} | |
// perform an asynchronous URL GET request and process when downloaded | |
let task = URLSession.shared.dataTask(with: classURL) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// data to save | |
// Note: This will work with any data, even Codable struct/class (which I suggest using) | |
let userData = [ "Firstname":"John", "Middle":"I", "LastName":"Doe" ] | |
// URL for file UserData.plist in user document directory for this app | |
let userDataURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("UserData").appendingPathExtension("plist") | |
// save the userData to the userDataURL | |
let encoder = PropertyListEncoder() | |
encoder.outputFormat = .xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>DepartmentName</key> | |
<string>CS</string> | |
<key>DepartmentNumber</key> | |
<string>3460</string> | |
<key>Name</key> | |
<string>iOS Development</string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.swift | |
// SwiftMasterDetailApp | |
// | |
// Created by Michael Collard on 2/6/18. | |
// Copyright © 2018 Michael Collard. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shifts the view up for space for the keyboard | |
NotificationCenter.default.addObserver(forName: NSNotification.Name.UIKeyboardWillShow, object: nil, queue: nil) { | |
notification in | |
print("\(notification.description)") | |
// find the size of the keyboard | |
guard let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue else { | |
print("ERROR: Unable to get keyboard size") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shifts the view up for space for the keyboard | |
NotificationCenter.default.addObserver(forName: NSNotification.Name.UIKeyboardWillHide, object: nil, queue: nil) { | |
notification in | |
print("\(notification.description)") | |
// move back to original position | |
self.view.frame.origin.y = 0 | |
} |