TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How Swift standard types and classes were supposed to work

10 pointsby gok2over 9 years ago

5 comments

cballardover 9 years ago
I think that at lot of these pollute the global scope unnecessarily or incorrectly, and many of them are semantically incorrect. It&#x27;s also a massive framework that doesn&#x27;t address a specific concern. It would be better packaged as a collection of μframeworks.<p>Some specific issues:<p>&gt; Easily access your ViewController on top of your view stack:<p><pre><code> let topOfMyViewStack = topMostVC </code></pre> UIKit supports an arbitrary number of windows, so &quot;your view stack&quot; is not something that is definable.<p>&gt; Easily access your screen width &amp; height:<p><pre><code> print(screenWidth) &#x2F;&#x2F; 375.0 on iPhone6 print(screenHeight) &#x2F;&#x2F; 667.0 on iPhone6 </code></pre> Which screen? iOS supports multiple screens - there&#x27;s a reason that these things are scoped to instance properties of UIScreen.<p>&gt; Easily run block of code:<p><pre><code> let myBlock = { print(&quot;lol&quot;) } runThisBlock(myBlock) </code></pre> You can just call it directly with myBlock() - which the implementation presumably does.<p>&gt; Easily convert between different types:<p><pre><code> var myDouble = myInt.toDouble </code></pre> Double(myInt) isn&#x27;t really hard, and the &quot;easy&quot; version is <i>more characters</i>.<p>&gt; Easily access ViewController sizes:<p>View controllers do not have sizes - views do.<p>I don&#x27;t want to rag on the author too much, but I&#x27;d also like to add something about the tagline &quot;How Swift standard types and classes were supposed to work&quot;. This seems needlessly offensive and incorrect - in all likelihood, Chris Lattner is smarter (or at least more educated on the subject) than you - or me! There&#x27;s no need to say that he&#x27;s doing his work incorrectly. Instead, a tagline like &quot;useful extensions for the Swift Standard Library, Foundation, and UIKit&quot; wouldn&#x27;t imply that the Swift team wasn&#x27;t doing their job. Save that for complaining about the inability to define a Monad protocol.
评论 #10597150 未加载
评论 #10597130 未加载
sandofskyover 9 years ago
This library provides so many anti-patterns. &quot;topMostVC&quot; is going to be the source of a ton of bugs.<p>As for aesthetics, this library will be adopted by a lot of people who don&#x27;t understand Cocoa conventions. If I saw it part of a project, I&#x27;d consider it a red flag.
评论 #10597013 未加载
jcizzleover 9 years ago
Some of this is just poor style&#x2F;naming conventions, some of it is simply implemented incorrectly and the rest of it removes necessary distinctions from important functionality.
评论 #10596993 未加载
masklinnover 9 years ago
The string indexing extensions are just terrible. There are good reasons why Swift does not provide these things out of the box even though objective-c did: <a href="http:&#x2F;&#x2F;oleb.net&#x2F;blog&#x2F;2014&#x2F;07&#x2F;swift-strings&#x2F;#character-indices-and-ranges" rel="nofollow">http:&#x2F;&#x2F;oleb.net&#x2F;blog&#x2F;2014&#x2F;07&#x2F;swift-strings&#x2F;#character-indice...</a>
评论 #10598081 未加载
sdegutisover 9 years ago
Actually, a default implementation of `random` on `CollectionType` isn&#x27;t such a bad idea.
评论 #10597111 未加载
评论 #10596979 未加载