Stanford University Open Class: iOS8 Development first Lesson: iOS8 Overview study notes
Last Update:2015-06-24
Source: Internet
Author: User
<span id="Label3"></p><span style="font-size:18px; color:#cc33cc; background-color:rgb(255,255,255)"><span style="font-size:18px; color:#cc33cc; background-color:rgb(255,255,255)"><br></span></span><span style="font-size:18px; color:#cc33cc; background-color:rgb(255,255,255)"><span style="font-size:18px; color:#cc33cc; background-color:rgb(255,255,255)">1. All objects, class. instances of the class are in the heap</span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc"><span style="font-family:‘Helvetica Neue‘; background-color:rgb(255,255,255)"></span></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc"><br></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc">2. Let represents a constant, and once you set an initial value for it, it cannot be changed within this method.</span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc"><br></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc">3. If you put a \ () in the string, you can put an expression in Parentheses. Swift evaluates the expression, and then converts the value into a string, which is then embedded in it, such as</span></span><span style="font-size:18px; font-family:Menlo; color:rgb(61,29,129)"><span style="font-size:18px; font-family:Menlo; color:rgb(61,29,129)">println</span></span><span style="font-size:18px; font-family:Menlo"><span style="font-size:18px; font-family:Menlo">(</span></span><span style="font-size:18px; font-family:Menlo; color:rgb(201,27,19)"><span style="font-size:18px; font-family:Menlo; color:rgb(201,27,19)">"digit =</span></span> <span style="font-size:18px; font-family:Menlo"><span style="font-size:18px; font-family:Menlo">\ (digit)</span></span><span style="font-size:14px; font-family:Menlo; color:rgb(201,27,19)"><span style="font-size:14px; font-family:Menlo; color:rgb(201,27,19)"><span style="font-size:18px">"</span></span></span><span style="font-size:14px; font-family:Menlo"><span style="font-size:14px; font-family:Menlo"><span style="font-size:18px">) </span></span></span><span style="font-family:Menlo"><span style="font-family:Menlo">Print out <span style="font-size:14px">is <strong>digit = Optional ("9")</strong> </span> <span style="font-size:18px"></span> </span></span><span style="font-family:‘Helvetica Neue‘; font-size:14px"><span style="font-family:‘Helvetica Neue‘; font-size:14px"></span></span><br><span style="font-family:‘Helvetica Neue‘; font-size:14px"><span style="font-family:‘Helvetica Neue‘; font-size:14px"></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc">4. There are only two types of Optional: 1. Not set: indicates that the value has not been set by anyone, or someone intentionally set it to an undefined state</span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc"><span style="font-family:‘Helvetica Neue‘"></span></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc">2. There are values:</span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc"><br></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc"><span style="font-family:‘Helvetica Neue‘"></span></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc">5. Swift is not a weak type. it is a very, very strong type of language. but Swift has a very powerful feature called type deduction</span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc"><span style="font-family:‘Helvetica Neue‘"></span></span></span><span style="font-size:18px; font-family:Menlo; color:rgb(195,34,117)"><span style="font-size:18px; font-family:Menlo; color:rgb(195,34,117)"></span> let</span><span style="font-size:18px; font-family:Menlo"><span style="font-size:18px; font-family:Menlo">digit = Sender.</span></span><span style="font-size:18px; font-family:Menlo; color:rgb(112,61,170)"><span style="font-size:18px; font-family:Menlo; color:rgb(112,61,170)">Currenttitle</span></span><span style="font-size:18px; font-family:Menlo"><span style="font-size:18px; font-family:Menlo">!</span></span><span style="font-family:‘Helvetica Neue‘; font-size:14px"><span style="font-family:‘Helvetica Neue‘; font-size:14px"></span></span><span style="font-size:18px"><span style="font-size:18px"><span style="font-family:Menlo"> </span></span></span><span style="font-family:Menlo"><span style="font-family:Menlo"><span style="font-size:18px; color:#cc33cc">6. The next exclamation mark is to unpack the optiona and get the real property, but if the property is empty it crashes</span></span></span><span style="font-size:18px; color:#cc33cc">the <span style="font-size:18px; color:#cc33cc">value must be assigned at initialization time</span></span><span style="font-size:14px"><span style="font-size:14px"></span></span><span style="font-size:18px; font-family:Menlo; color:rgb(195,34,117)"><span style="font-size:18px; font-family:Menlo; color:rgb(195,34,117)">var</span></span><span style="font-size:14px"><span style="font-size:14px"></span></span><span style="font-size:18px; font-family:Menlo"><span style="font-size:18px; font-family:Menlo">ishavetext:</span></span><span style="font-size:14px"><span style="font-size:14px"></span></span><span style="font-size:18px; font-family:Menlo; color:rgb(112,61,170)"><span style="font-size:18px; font-family:Menlo; color:rgb(112,61,170)">Bool</span></span><span style="font-size:14px"><span style="font-size:14px"></span></span><span style="font-size:18px; font-family:Menlo"><span style="font-size:18px; font-family:Menlo">=</span></span><span style="font-size:14px"><span style="font-size:14px"></span></span><span style="font-size:18px; font-family:Menlo; color:rgb(195,34,117)"><span style="font-size:18px; font-family:Menlo; color:rgb(195,34,117)">false</span></span><span style="font-family:‘Helvetica Neue‘; font-size:14px"><span style="font-family:‘Helvetica Neue‘; font-size:14px"></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc">7. If you do not unpack it directly for operation, such as:</span></span><span style="font-family:Menlo; color:rgb(79,129,135)"><span style="font-family:Menlo; color:rgb(79,129,135)"> <span style="font-size:14px"> </span> <span style="font-size:18px">display</span> </span></span><span style="font-size:18px"><span style="font-size:18px"><span style="font-family:Menlo">.</span> <span style="font-family:Menlo; color:rgb(112,61,170)">text</span> <span style="font-family:Menlo">= digit +</span> <span style="font-family:Menlo; color:rgb(79,129,135)">Display</span> <span style="font-family:Menlo">.</span></span></span><span style="font-family:Menlo; color:rgb(112,61,170)"><span style="font-family:Menlo; color:rgb(112,61,170)"><span style="font-size:18px">text</span></span></span><span style="font-size:18px; color:#cc33cc"><span style="font-size:18px; color:#cc33cc"> <span style="font-family:‘Helvetica Neue‘">The compiler will not know its type Error.</span><br></span></span><br>All code<br><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#bb2ca2">class</span> Viewcontroller:<span style="color:#703daa">Uiviewcontroller</span> {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#bb2ca2">@IBOutlet</span> <span style="color:#bb2ca2">Weak</span> <span style="color:#bb2ca2">var</span> display: <span style="color:#703daa">UILabel</span>!</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#bb2ca2">var</span> userisinthemiddleoftypingannumber: <span style="color:#703daa">Bool</span> = <span style="color:#bb2ca2">false</span>;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#bb2ca2">@IBAction</span> <span style="color:#bb2ca2">func</span> numberbuttonclick (sender:<span style="color:#703daa">UIButton</span>) {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#bb2ca2"></span> let digit = Sender. <span style="color:#703daa">currenttitle</span>!</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(79,129,135)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(79,129,135)"><span style="color:#000000"> </span> <span style="color:#bb2ca2"></span>if<span style="color:#000000"></span>userisinthemiddleoftypingannumber<span style="color:#000000"> {</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#4f8187">display</span>. <span style="color:#703daa">text</span> = digit +<span style="color:#4f8187">display</span>. <span style="color:#703daa">text</span>!</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}<span style="color:#bb2ca2">Else</span> {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#4f8187">display</span>. <span style="color:#703daa">text</span> = digit</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(79,129,135)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(79,129,135)"><span style="color:#000000"> </span>userisinthemiddleoftypingannumber<span style="color:#000000"> =</span><span style="color:#bb2ca2">true</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#3d1d81">println</span> (<span style="color:#d12f1b">"digit = </span>\<span style="color:#d12f1b">(</span>digit<span style="color:#d12f1b">)"</span>)</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><br><span style="font-family:‘Helvetica Neue‘; font-size:14px"><span style="font-family:‘Helvetica Neue‘; font-size:14px"></span></span><p><p>Stanford University Open Class: iOS8 Development first Lesson: iOS8 Overview study notes</p></p></span>