Ana sayfa iOS Swift 4 – Type Alias Kullanımı

Swift 4 – Type Alias Kullanımı


Merhaba arkadaşlar,

Bugünkü dersimizde Type Alias kullanımından bahsedeceğiz.

Type Alias sayesinde, hali hazırda var olan tipleri dilediğimiz şekilde adlandırabiliriz.

Bazen kod yazarken, kodumuzun içeriğine bağlı olarak kullandığımız class struct vb. gibi tipleri farklı adlandırmak, daha mantıklı olabiliyor.

Aşağıdaki örneğimizi inceleyerek daha iyi anlamaya çalışalım:

Öncelikle Car adında yalnızca model özelliğine sahip olan bir araba sınıfı yaratalım.

Daha sonra aşağıdaki gibi arabalardan oluşacak olan boş bir array oluşturalım:

Burada okunulurluğu artırabilmek adına “Array<Car>” tanımlamasını Type Alias yardımıyla “Cars” olarak belirteceğiz ve ilerde arabalardan oluşan başka bir array tanımlamak istediğimizde daha okunur ve kısa bir şekilde tanımlama yapabileceğiz.

typealias’ı ayarladıktan sonra artık objemizin tipini kısaca Cars olarak belirtebiliyoruz.

Ayrıca typealias yardımıyla değiştirdiğimiz tipin metodlarını kullanmaya devam edebiliyoruz. Örneğin yukarıdaki örneğimizde bir array’e typealias yaptığımız için, typealias ile tanımlanan “newCars” array’inde normal array metodlarımızı kullanabiliriz:

Hata almadan array metodu olan .count’u burada da kullanabildik.

Type Alias zaman zaman okunulurluğu artırmada ve temiz kod yazmada büyük rol oynayabiliyor. Özellikle closure, ve tuple gibi yerlerde çok etkili olabiliyor.

Type Alias’ı basitçe görmeye çalıştık, umarım faydalı olmuştur.

Bir sonraki dersimizde görüşmek üzere 🙂


  1. You could definitely see your enthusiasm within the paintings you write. The arena hopes for even more passionate writers such as you who are not afraid to mention how they believe. At all times follow your heart.

  2. Oh my goodness! an incredible article dude. Thank you Nonetheless I’m experiencing subject with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting similar rss problem? Anyone who knows kindly respond. Thnkx

  3. Hello, Neat post. There’s an issue together with your website in internet explorer, would test thisK IE still is the market chief and a good part of folks will pass over your excellent writing because of this problem.

  4. obviously like your website but you have to check the spelling on several of your posts. Several of them are rife with spelling problems and I find it very bothersome to tell the truth nevertheless I will definitely come back again.

  5. I like what you guys are up too. Such smart work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my site 🙂

  6. Hi there just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Internet explorer. I’m not sure if this is a format issue or something to do with internet browser compatibility but I thought I’d post to let you know. The layout look great though! Hope you get the issue solved soon. Many thanks

  7. Awesome site you have here but I was wanting to know if you knew of any forums that cover the same topics discussed in this article? I’d really like to be a part of community where I can get suggestions from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Cheers!

  8. obviously like your web-site however you have to take a look at the spelling on quite a few of your posts. Several of them are rife with spelling issues and I to find it very troublesome to tell the truth then again I will definitely come again again.

  9. There are some attention-grabbing cut-off dates on this article however I don’t know if I see all of them center to heart. There may be some validity but I’ll take hold opinion till I look into it further. Good article , thanks and we wish extra! Added to FeedBurner as effectively

  10. I simply wanted to construct a simple note to be able to thank you for these splendid suggestions you are writing at this site. My time consuming internet research has at the end of the day been rewarded with extremely good facts to talk about with my close friends. I ‘d suppose that we site visitors are very blessed to dwell in a wonderful network with so many lovely people with useful basics. I feel very lucky to have encountered your entire site and look forward to so many more brilliant minutes reading here. Thanks a lot again for a lot of things.

  11. I do agree with all the concepts you have offered for your post. They’re really convincing and can certainly work. Nonetheless, the posts are too quick for newbies. May just you please extend them a bit from subsequent time? Thank you for the post.

  12. It’s the best time to make some plans for the future and it is time to be happy. I have learn this post and if I may just I wish to recommend you some fascinating things or suggestions. Maybe you could write next articles referring to this article. I want to read more things approximately it!

  13. Hey There. I found your blog using msn. This is a really well written article. I will be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely comeback.

  14. I like the valuable information you provide on your articles. I’ll bookmark your blog and test again right here frequently. I’m reasonably certain I’ll learn a lot of new stuff proper here! Good luck for the next!

  15. Appreciating the commitment you put into your site and in depth information you present. It’s nice to come across a blog every once in a while that isn’t the same outdated rehashed material. Wonderful read! I’ve saved your site and I’m adding your RSS feeds to my Google account.

  16. I needed to write you one very small word to finally thank you once again for your nice ideas you’ve shown here. This has been simply remarkably generous with people like you to convey freely just what a few individuals could possibly have offered as an ebook to help make some cash for their own end, chiefly given that you could possibly have tried it if you desired. The pointers also acted to be a fantastic way to understand that other people have a similar desire much like mine to see lots more in terms of this condition. I believe there are a lot more fun sessions in the future for individuals who look over your site.

  17. I haven’t checked in here for some time as I thought it was getting boring, but the last several posts are good quality so I guess I will add you back to my everyday bloglist. You deserve it my friend 🙂

  18. Hmm it looks like your blog ate my first comment (it was extremely long) so I guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog. I too am an aspiring blog blogger but I’m still new to everything. Do you have any helpful hints for newbie blog writers? I’d definitely appreciate it.

  19. Good – I should definitely pronounce, impressed with your web site. I had no trouble navigating through all the tabs and related info ended up being truly easy to do to access. I recently found what I hoped for before you know it in the least. Quite unusual. Is likely to appreciate it for those who add forums or something, web site theme . a tones way for your customer to communicate. Nice task..

  20. Hiya, I’m really glad I’ve found this information. Nowadays bloggers publish only about gossips and web and this is actually annoying. A good blog with interesting content, that is what I need. Thank you for keeping this web site, I’ll be visiting it. Do you do newsletters? Cant find it.

  21. This design is spectacular! You definitely know how to keep a reader amused. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!

  22. Hi, I think your site might be having browser compatibility issues. When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, fantastic blog!

  23. It’s a shame you don’t have a donate button! I’d definitely donate to this outstanding blog! I guess for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to brand new updates and will share this website with my Facebook group. Talk soon!

  24. Nice read, I just passed this onto a colleague who was doing a little research on that. And he just bought me lunch because I found it for him smile Therefore let me rephrase that: Thank you for lunch! “To be 70 years young is sometimes far more cheerful and hopeful than to be 40 years old.” by Oliver Wendell Holmes.

  25. What i do not understood is in reality how you are no longer actually a lot more neatly-liked than you may be now. You’re very intelligent. You know therefore considerably in relation to this subject, made me individually consider it from numerous numerous angles. Its like women and men aren’t interested except it is something to accomplish with Lady gaga! Your individual stuffs nice. At all times take care of it up!


Lütfen yorumunuzu giriniz
Buraya isminizi giriniz