{"id":18030365,"url":"https://github.com/jhurray/beginning-ios-in-swift-workshop","last_synced_at":"2025-09-23T16:33:04.167Z","repository":{"id":76688187,"uuid":"45057792","full_name":"jhurray/Beginning-iOS-in-Swift-Workshop","owner":"jhurray","description":"Blank template project for the beginning iOS seminar I ran for Yahoo at the University of Michigan","archived":false,"fork":false,"pushed_at":"2015-10-28T22:08:08.000Z","size":16676,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-12T00:33:05.093Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jhurray.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-27T17:25:31.000Z","updated_at":"2016-03-29T21:49:21.000Z","dependencies_parsed_at":"2023-03-09T04:15:28.519Z","dependency_job_id":null,"html_url":"https://github.com/jhurray/Beginning-iOS-in-Swift-Workshop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jhurray/Beginning-iOS-in-Swift-Workshop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurray%2FBeginning-iOS-in-Swift-Workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurray%2FBeginning-iOS-in-Swift-Workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurray%2FBeginning-iOS-in-Swift-Workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurray%2FBeginning-iOS-in-Swift-Workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jhurray","download_url":"https://codeload.github.com/jhurray/Beginning-iOS-in-Swift-Workshop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhurray%2FBeginning-iOS-in-Swift-Workshop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271745595,"owners_count":24813509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T09:14:08.636Z","updated_at":"2025-09-23T16:32:59.107Z","avatar_url":"https://github.com/jhurray.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"#Beginning iOS development in Swift\n\nWelcome to the Swift iOS development crash course, sponsored by Yahoo. In the next 2 hours you will create an iOS application written in Swift, Apple's new programming language.\n\n###Prerequisites\nPlease have the latest Version of XCode (7.0) installed. You will need an Apple computer so if you don't have one please borrow one from a friend and make sure you have XCode installed.\n\nXcode takes about 15 minutes to install so please don't wait until we start to install it.\n\n### The Project\nWe will be createing an anonymous social network that lets you post and read other peoples posts. It will be very basic and bare bones, but it wil be a functional app. \n\n\n#Swift Cheat Sheet\n\n##Declaring Variables\nSwift variables are either mutable or immutable. Variables are declared with ```let``` and ```var``` respectively.\n\n```swift\n\nlet myContstantInt = 1\nvar myMutableInt = 1\n\nmyMutableInt++ // this works\nmyContstantInt++ // Error: myContstantInt is immutable\n\nlet myConstantArray = [\"hello\"] \nvar myMutableArray = [\"hello\"] \n\nmyMutableArray.append(\"world\") // this works\nmyConstantArray.append(\"world\") // Error: myConstantArray is immutable\n\n```\n\n##Casting\nCasting in swift is done with ```:```\n\n```swift\nlet myNumber1 = 12.0 // this is implicityly typed as a Float\nlet myNumber2 = 12 // this is implicitly typed as an Int\nlet myFloat : Float = 12 // this is explicityly typed as a Float\nlet myInt : Int = 12.0 // this is explicitly typed as an Int\n```\n\nYou can also cast from one type to another with the ```as``` operator.\n\n```swift\nlet arrayOfFloats = [12.5, 1.4, 2.0] as Array\u003cFloat\u003e \n```\n\n##Low level Data Types\n  * Int\n  * Float\n  * Double\n  * String\n  * Array\n  * Dictionary\n  * Closure\n\n###Int, Float, Double\nThese all are pretty basic. You can cast from one to the other using constructors.\n\n```swift\nlet myFloat : Float = 12.5\nlet myInt : Int = Int(myFloat) // 12\n\nlet sum : Double = Double(myFloat) = Double(myInt) // 24.5\n```\n\n###String\nStrings in swift are super flexible and extendible.\n\n```swift\nvar greetings = \"hello \" + \"world\"\n\ngreetings += \". Whatsup party people?!?\"\n```\nYou can add variables in strings by wrapping them with ```\\()```\n\n```swift\nlet myAge = 21\nlet myString = \"I am \\(myAge) years old.\"\n```\n\n###Array\nArrays in swift can be casted in 2 ways:\n\n```swift\nvar myArray : [String] = [String]()\nvar myOtherArray : Array\u003cString\u003e = Array\u003cString\u003e()\n\nmyArray.dynamicType == myOtherArray.dynamicType // True\n```\n\nAdd to an array with ```append()``` and get / set elements with the ```[]``` operator.\n\n```swift\nmyArray.append(\"hello\")\n\nmyArray[0] = \"world\"\n\nprint(myArray) // [\"world\"]\n\n```\n\n###Dictionary\nDictionarys in swift can be casted in 2 ways as well:\n\n```swift\nclass MyObject {}\n\nvar myDict : [String : MyObject] = [String : MyObject]()\nvar myOtherDict : Dictionary\u003cString, MyObject\u003e = Dictionary\u003cString, MyObject\u003e()\n\nmyDict.dynamicType == myOtherDict.dynamicType // True\n```\n\nGet and set objects with the ```[]``` operator.\n\n```swift\nmyDict[\"myKey\"] = MyObject()\n```\n\n###Closures\n\nClosures are very similar to those in Javascript. They are usually used as completion blocks in functions to control execution flow but can also be used as for calculation and building UI elements. In this case they act like functions but they can be passed around as variables!\n\n```swift\nlet doubleMyInt : (Int) -\u003e Int = { (n) -\u003e Int in\n    return n * 2\n}\n\nlet tenTimesMyInt : (Int) -\u003e Int = { (n) -\u003e Int in\n    return 10 * n\n}\n\nlet shouldBe6 = doubleMyInt(3)\n\nfunc doSomething(n : Int, mutator : (Int)-\u003e(Int)) -\u003e Int {\n    return mutator(n)\n}\n\nlet shouldBe6Again = doSomething(3, mutator: doubleMyInt)\n\nlet shouldBe30 = doSomething(3, mutator: tenTimesMyInt)\n```\n\nYou can declare a closure as a type using ```typealias```\n\n```swift\ntypealias IntToIntClosure = (Int) -\u003e Int\n\nfunc doSomething(n : Int, mutator : IntToIntClosure) -\u003e Int {\n\treturn mutator(n)\n}\n```\n\n##Functions\n\nFunctions are very flexible in swift.\n\n```swift\n// In this case a and b are parameters. b can not be defined, and if it is left black it will default to the value that is set after it.\nfunc myFunction(a : Int, b : String = \"My Default String\") {\n\tprint(\"a = \\(a) and b = \\(b)\")\n}\n\nmyFunction(12, b: \"Hello World\") // \"a = 12 and b = Hello World\"\n\nmyFunction(12) // \"a = 12 and b = My Default String\"\n\n```\n\nTo set a return value from a function use ```-\u003e``` followed by the value you want returned. You can even return tuples in Swift.\n\n```swift\nfunc returnsAnArray() -\u003e [Any] {\n\treturn []\n}\n\nfunc returnsAnArrayOfStrings() -\u003e [String] {\n\treturn [\"Hello\", \"World\"]\n}\n\nfunc returnsATuple() -\u003e (Int, String, [Float]) {\n    return (3, \"a\", [12.0, 9.0])\n}\n```\n\n\n#iOS Cheat Sheet - An overview of Apples API\n\n##UIKit\n\nUIKit is a library written by Apple that provides developers with basic UI Elements for iOS development. Thes classes can be customized, extended, and subclassed. Examples of view classes include **UIView, UIImageView, UIlabel, UITextField, and UIButton**\n\n####UIViewController\nAny screen you see on an iOS app is held in a UIViewController. Its purpose is to control all the views in the screen and handle the passing of data into views.\n\n####UINavigationController\nUINavigationControllers hold view controllers and control their navigation. When you press a button and you switch screens on an iOS app this is almost lways done through a UINavigationController\n\n####UITableView\nUITableView is the most basic way to display data sets. Most iOS applications use table views. TableViews use **UITableViewCells** to display data. If you have an array of 50 strings you can use a tableView to display those strings in 50 rows.\n\n##Delegate Pattern\nA widely used design pattern in iOS development is the Delegate pattern. \n\n####Protocols\nA protocol is a set of functions that an class must conform to. An example of this is the **UITableViewDelegate**.\n\n```swift\nprotocol HasNickname {\n    func nickname() -\u003e String\n}\n\nclass Person : HasNickname {\n    \n    func greeting() -\u003e String {\n        return \"Hi you can call me \\(self.nickname())\"\n    }\n    \n    func nickname() -\u003e String {\n        return \"\"\n    }\n}\n\nclass Teacher : Person {\n    \n    override func nickname() -\u003e String {\n        return \"Mr. Jones\"\n    }\n    \n}\n\nclass Friend : Person {\n    override func nickname() -\u003e String {\n        return \"Buddy\"\n    }\n}\n\nlet teacher = Teacher()\nlet friend = Friend()\n\n// Prints: \"Hi you can call me Mr. Jones\"\nprint(teacher.greeting())\n\n// Prints: \"Hi you can call me Buddy\"\nprint(friend.greeting())\n\n```\n\n####Delegates \nDelegates can be used to do things for your class. UITableView uses its delegate to control when a row is tapped, and many other things. UITextView uses its delegate to know if it should begin editing, end editing, and whether to change its text. \n\n```swift\n\nprotocol PersonGreetingDelegate {\n    func personDidSayHello()\n    func personDidSayGoodbye()\n}\n\nclass Person {\n    \n    var greetingDelegate : PersonGreetingDelegate?\n    \n    func sayHello() {\n        print(\"hello!\")\n        self.greetingDelegate!.personDidSayHello()\n    }\n    \n    func sayGoodbye() {\n        print(\"goodbye!\")\n        self.greetingDelegate!.personDidSayGoodbye()\n    }\n}\n\nclass Robot : PersonGreetingDelegate {\n    var companion : Person?\n    \n    func setPerson(person : Person) {\n        companion = person\n        companion!.greetingDelegate = self\n    }\n    \n    func personDidSayHello() {\n        print(\"Greetings I am a robot\")\n    }\n    \n    func personDidSayGoodbye() {\n        print(\"Goodbye my human friend\")\n    }\n}\n\nclass Dog : PersonGreetingDelegate {\n    var owner : Person?\n    \n    func setPerson(person : Person) {\n        owner = person\n        owner!.greetingDelegate = self\n    }\n    \n    func personDidSayHello() {\n        print(\"Woof woof!\")\n    }\n    \n    func personDidSayGoodbye() {\n        print(\"Bark bark!\")\n    }\n}\n\nlet person = Person()\nlet robot = Robot()\nlet dog = Dog()\n\nrobot.setPerson(person)\ndog.setPerson(person)\n\nperson.sayHello()\n// Prints:\n// hello! \n// Greetings I am a robot\n// Woof woof\n\nperson.sayGoodbye()\n//Prints:\n// goodbye!\n// Goodbye my human friend\n// Bark bark!\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhurray%2Fbeginning-ios-in-swift-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhurray%2Fbeginning-ios-in-swift-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhurray%2Fbeginning-ios-in-swift-workshop/lists"}