{"id":816,"date":"2016-01-24T12:18:07","date_gmt":"2016-01-24T12:18:07","guid":{"rendered":"http:\/\/coolt.ch\/notizen\/?p=816"},"modified":"2016-01-24T12:18:07","modified_gmt":"2016-01-24T12:18:07","slug":"swift-introduction","status":"publish","type":"post","link":"https:\/\/coolt.ch\/notizen\/swift-introduction\/","title":{"rendered":"swift introduction"},"content":{"rendered":"<p><strong>Implizite Typzuweisung<br \/>\n<\/strong>Der Datentyp muss nicht angegeben werden. Vor dem Variablenname definiert man nur, ob es sich um eine Konstante <span class=\"lang:sh decode:true  crayon-inline \">let<\/span>\u00a0 oder eine Variable <span class=\"lang:sh decode:true  crayon-inline \">var<\/span>\u00a0 handelt.<strong><br \/>\n<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">let length_box = 5                 \/\/ wird zu int\r\nlet hight_box = 3.5                \/\/ wird zu float\r\nlet projectname = \"ImageRecover\"   \/\/ wird zu string \r\nvar number = 2\r\nvar isPressed = true               \/\/ bool<\/pre>\n<p>Konstanten sind Variablen vorzuziehen. <span class=\"lang:sh decode:true crayon-inline\">let area = Squar(length:5) <\/span><br \/>\n<strong><\/p>\n<p>Explizite Typzuweisung<br \/>\n<\/strong>Nach dem Variablenname kann \u00fcber <span class=\"lang:sh decode:true  crayon-inline\">:<\/span> den Datentyp definiert werden.<\/p>\n<pre class=\"lang:sh decode:true\">var number: Int16 = 2\u00a0\u00a0      \/\/ Integer definieren\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0  \r\nlet matrix:[Int16]<\/pre>\n<p><strong><br \/>\nNullpointer <\/strong><\/p>\n<pre class=\"lang:sh decode:true\">var device: MTLDevice!;        \/\/Typ ist MTLDevice mit Nullpointer\r\n<\/pre>\n<p><strong><br \/>\nAusf\u00fchren nur bei Objekten mit Inhalt<br \/>\n<\/strong>Sind Variablen, Funktionen oder Klassen mit<strong><span class=\"lang:sh decode:true crayon-inline \"> ?<\/span>\u00a0 <\/strong>definiert, wird der Code nur <strong>ausgef\u00fchrt<\/strong> (bzw. ein Wert zugewiesen), <strong>wenn<\/strong> das Objekt einen<strong> Wert enth\u00e4lt.<br \/>\n<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">var answer: String?         \/\/ answer erh\u00e4lt Wert nur, wenn String Inhalt hat\r\nvar error: NSError? \r\nvar age: Int?               \/\/ variable hat initalwert.<\/pre>\n<section class=\"code-listing\">\n<pre class=\"lang:sh decode:true\">if answer {                \/\/answer ! nil\r\n.    \/\/ do\r\n}\r\n\r\nif age {                  \/\/ nur wenn age einen Wert hat\r\n.   \/\/ do\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Implizite Typzuweisung Der Datentyp muss nicht angegeben werden. Vor dem Variablenname definiert man nur, ob es sich um eine Konstante let\u00a0 oder eine Variable var\u00a0 handelt. let length_box = 5 \/\/ wird zu int let hight_box = 3.5 \/\/ wird zu float let projectname = &#8222;ImageRecover&#8220; \/\/ wird zu string var number = 2 var &hellip; <a href=\"https:\/\/coolt.ch\/notizen\/swift-introduction\/\" class=\"more-link\"><span class=\"screen-reader-text\">swift introduction<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/posts\/816"}],"collection":[{"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/comments?post=816"}],"version-history":[{"count":6,"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/posts\/816\/revisions"}],"predecessor-version":[{"id":1178,"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/posts\/816\/revisions\/1178"}],"wp:attachment":[{"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/media?parent=816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/categories?post=816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coolt.ch\/notizen\/wp-json\/wp\/v2\/tags?post=816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}