Skip to content

Instantly share code, notes, and snippets.

View mansi-27's full-sized avatar
🎯
Focusing

Mansi Shah mansi-27

🎯
Focusing
View GitHub Profile
import Foundation
public extension FileManager {
// Returns a URL that points to the document folder of this playground.
static var documentDirectoryURL: URL {
return try! FileManager.default.url(
for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: false
do {
/// Specify a URL where you want to save the myAPIKeys.plist file with proper extension and pathComponent.
let plistURL = URL(fileURLWithPath: "myAPIKeys", relativeTo: FileManager.documentDirectoryURL.appendingPathComponent("MyPlistFolder")).appendingPathExtension("plist")
/// Create an instance of PropertyListEncoder()
/// Specifying outputFormat as `xml` so that you can view it in a source code file format or plist file format.
/// After that, encode your array of keys that you created above
/// And finally, write the encoded Data to your myAPIKeys.plist file.
/// Voila!
let documentSubdirectoryURL = URL(
fileURLWithPath: "MyPlistFolder",
relativeTo: FileManager.documentDirectoryURL
)
try? FileManager.default.createDirectory(
at: documentSubdirectoryURL,
withIntermediateDirectories: false
)
let myKeys = [
MyKey(
keyName: "facebookAPIKey",
keyValue: "ValueOfMyFacebookAPIKey",
type: .facebook),
MyKey(
keyName: "twitterAPIKey",
keyValue: "ValueOfMyTwitterAPIKey",
type: .twitter)]
struct MyKey: Codable {
enum Social: String, Codable {
case twitter, facebook
}
init(keyName: String, keyValue: String, type: Social) {
self.apiKeyName = keyName
self.apiKeyValue = keyValue
self.keyType = type
}
let apiKeyName: String
@IBAction func btnHorizontalFlipTapped(_ sender: UIButton) {
let presentationVC = ThirdViewController()
presentationVC.modalTransitionStyle = .flipHorizontal
present(presentationVC, animated: true, completion: nil)
}
@IBAction func btnPageCurlTapped(_ sender: UIButton) {
let presentationVC = ThirdViewController()
presentationVC.modalTransitionStyle = .partialCurl
present(presentationVC, animated: true, completion: nil)
// MARK: - IBActions
@IBAction func btnNavigateTapped(_ sender: UIButton) {
/// πŸ‘‰πŸΌ Add your animation before you push/pop the view controller
navigationController?.addTransition()
/// πŸ‘‰πŸΌ Don't forget to set the default animated property to FALSE
navigationController?.pushViewController(SecondViewController(), animated: false)
}
@IBAction func btnGoBackTapped(_ sender: UIButton) {
/// πŸ‘‰πŸΌ Add your animation before you push/pop the view controller
@mansi-27
mansi-27 / UINavigationController+Extensions.swift
Created December 16, 2017 19:13
Add Transition Animation in Swift
import UIKit
extension UINavigationController {
func addTransition() {
/// First, we initiate a CATransition object
let transition = CATransition()
/// Second, we define the duration for the transition to get COMPLETED
transition.duration = 1.0
/// Here, you define the animation pacing (whether it starts slowly, ends faster OR starts faster, ends slowly... etc)