{"id":1087,"date":"2018-03-19T14:19:58","date_gmt":"2018-03-19T14:19:58","guid":{"rendered":"http:\/\/sezeromer.com\/?p=1087"},"modified":"2023-02-26T13:27:52","modified_gmt":"2023-02-26T10:27:52","slug":"swift-timer-kullanimi","status":"publish","type":"post","link":"https:\/\/sezeromer.com\/en\/swift-timer-kullanimi\/","title":{"rendered":"Swift Using Timer"},"content":{"rendered":"<p>As in most programming languages, time is also very important in <strong>Swift<\/strong>. Especially the present time is usually when we are in the practice of growing up. Of course, this program may show changes in the program. To use time in Swift we need to define a variable and get that variable from <strong>Timer<\/strong> class. To summarize the Timer class in brief, it is the class where we have the functions to grow in our business. Without writing a lot of code on this page, we can reach what we want.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1088\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/03\/swift-timer-1.png\" sizes=\"(max-width: 1133px) 100vw, 1133px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/03\/swift-timer-1.png 1133w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/03\/swift-timer-1-300x144.png 300w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/03\/swift-timer-1-768x367.png 768w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/03\/swift-timer-1-1024x490.png 1024w\" alt=\"\" width=\"1133\" height=\"542\" \/><\/p>\n<p>Let&#8217;s make a narrative of them through a scenario. First, let&#8217;s take the time and date now. For this we define two variables named TimeFormatter and DateFormatter. After that, we need to give some style to these variables. If the time is a date through <strong>timeStyle<\/strong>, then we give it a <strong>dateStyle<\/strong>. The purpose for which we give these pictures is concerned with how much information we provide about time or date. For example, if you select Style <strong>Medium<\/strong>, you will see the time, minute, and second, while selecting full in the style section will give you the screen as much as I use the time zone. On this count, we can get time and seconds.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">let saatFormatter = DateFormatter()\r\n        saatFormatter.timeStyle=DateFormatter.Style.medium\r\n        \r\n        let tarihFormatter = DateFormatter()\r\n        tarihFormatter.dateStyle=DateFormatter.Style.medium<\/pre>\n<\/div>\n<p>If you want to display the current time and date continuously on the screen, you have to use the timer. For this, we created a variable called a counter. We will use this to take the time again. We can do this with the function below. To explain the function, timeInerval tells you how many seconds it will work. When you ask where you will give it as your goal, you will target yourself. As a selector you also specify which function will work. Inside this function you will also add the time and date to the top and drop them into a label and refresh it within the time you want and display it in the labs.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\">sayac = Timer.scheduledTimer(timeInterval: 1, target: self, selector: (#selector(self.guncelle)), userInfo: nil, repeats: true)<\/pre>\n<\/div>\n<p>If you have any questions, please contact me by email or comment.<\/p>","protected":false},"excerpt":{"rendered":"<p>As in most programming languages, time is also very important in Swift. Especially the present time is usually when we are in the practice of growing up. Of course, this program may show changes in the program. To use time in Swift we need to define a variable and get that variable from Timer class. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1095,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[327],"tags":[358,364,115,151,361,328,360,359,362,363],"class_list":["post-1087","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swift","tag-date","tag-dateformatter","tag-ios","tag-label","tag-saat","tag-swift","tag-tarih","tag-time","tag-timer","tag-zaman"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1087"}],"collection":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/comments?post=1087"}],"version-history":[{"count":4,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1087\/revisions"}],"predecessor-version":[{"id":2579,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/1087\/revisions\/2579"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media\/1095"}],"wp:attachment":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media?parent=1087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/categories?post=1087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/tags?post=1087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}