Learning IOS Development

The information below includes definitions, examples, projects, and overall any documentation of information that will help me retain and display what I know. The content is organized in chronological order to show improvement with the most recent at the top of the page.


Animation Transition App

Gif created from ios simulator

Frame Animation App

Screenshots/Gif from ios simulator

What's The Weather App

Screenshots from ios simulator

Manipulating Strings Playground

Screenshot from Xcode

Downloading Web Content

I created an application that downloads content from the web like the html of the webpage following a tutorial within an ios course I purchased on Udemy.

Using WebKit View

You must import WebKit in order to use a WKWebView. You can assign a variable to the method URL() and pass it a string url. Below is a snippet of code showing how to retrieve the html code from a website. It is also an example of asynchronous or multithreaded programming which is good for setting up the user interface or displaying a loading message for the user while waiting for the data to come back.

@IBOutlet weak var webview: WKWebView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        if let myurl = URL(string: "https://cassiequach.com") {
        
//        webview.load(URLRequest(url: myurl)) //this loads the webpage the url points to into the webview
            let request = NSMutableURLRequest(url: myurl)
            
            let task = URLSession.shared.dataTask(with: request as URLRequest) {
                data, response, error in
                
                if let error = error {
                    print(error)
                } else {
                    if let unwrappedData = data {
                        let dataString = NSString(data: unwrappedData, encoding: String.Encoding.utf8.rawValue)
                        print(dataString ?? "")
                    }
                }
            } //happens at same time as task.resume() below
            task.resume()
            
        }
    }

Creating a To-Do list app

I created a To-Do List application following a tutorial within an ios course I purchased on Udemy. Below are the key take-aways from completing the tutorial.

Permanent Data Storage

The code below retrieves and sets/saves permanent data storage within the application using a key to set and retrieve the right data. Usually you would modify the object after retrieving based on user input and then proceed to save it once the user is done modifying.

let object = UserDefaults.standard.object(forKey: "items")
                                    
UserDefaults.standard.set(object, forKey: "items")

Controlling the Keyboard

In order to be able to tap outside of the keyboard area or hit the return button to close the keyboard, the code below needs to be added to the view controller code containing the textfield.

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            
    self.view.endEditing(true)
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {

    textField.resignFirstResponder()
    
    return true
}

viewDidAppear versus viewDidLoad

The viewDidLoad function is called when the app is first loaded while the viewDidAppear function is called everytime that view controller appears on screen. For the purposes of creating a To-Do List app, if we add an item on the second view controller, the first view controller which contains the list of things to do must be reloaded without needing to close and launch the app again. In this case, we should use the viewDidAppear method to reload the data rather than the viewDidLoad method as shown below.

override func viewDidLoad() {
                                
    super.viewDidLoad()
    
    // Do any additional setup after loading the view.

}

override func viewDidAppear(_ animated: Bool) {

    let itemsObject = UserDefaults.standard.object(forKey: "items")

    if let tempItems = itemsObject as? [String] {

        items = tempItems

    }
    table.reloadData()
}