Moving Swiftlyhtml, body {overflow-x: initial !important;}html { font-size: 14px; }
body { margin: 0px; padding: 0px; height: auto; bottom: 0px; top: 0px; left: 0px; right: 0px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1rem; line-height: 1.42857143; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); overflow-x: hidden; }
a:active, a:hover { outline: 0px; }
::selection { background-color: rgb(181, 214, 252); text-shadow: none; background-position: initial initial; background-repeat: initial initial; }
#write { max-width: 854px; margin: 0px auto; height: auto; width: inherit; word-break: normal; word-wrap: break-word; position: relative; white-space: pre-wrap; text-align: justify; padding-bottom: 70px; }
body.typora-export { padding-left: 30px; padding-right: 30px; }
.typora-export #write { margin: 0px auto; }
#write > p:first-child, #write > ul:first-child, #write > pre:first-child, #write > blockquote:first-child, #write > div:first-child { margin-top: 30px; }
img { max-width: 100%; }
input, button, select, textarea { color: inherit; font-family: inherit; font-size: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
::before, ::after, * { box-sizing: border-box; }
#write p, #write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write div, #write pre { width: inherit; }
h1 { font-size: 2rem; }
p, .mathjax-block { display: block; -webkit-margin-before: 1rem; -webkit-margin-after: 1rem; -webkit-margin-start: 0px; -webkit-margin-end: 0px; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: bold; font-style: italic; }
a { cursor: pointer; }
li span { min-width: 10px; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; margin: 4px 0px 0px; }
tr { page-break-inside: avoid; page-break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; page-break-inside: auto; }
table.md-table td { min-width: 80px; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror-code pre { padding: 0px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
.md-fences, pre.md-fences { font-size: 0.9rem; display: block; page-break-inside: avoid; text-align: left; overflow: visible; white-space: pre; position: relative !important; }
.md-fences .CodeMirror.cm-s-default.CodeMirror-wrap { top: -1.6em; margin-bottom: -1.6em; }
.md-fences.mock-cm { white-space: pre-wrap; }
.footnotes { color: rgb(136, 136, 136); font-size: 0.9rem; padding-top: 1em; padding-bottom: 1em; }
.footnotes + .footnotes { margin-top: -1em; }
sub, sup { line-height: inherit; position: inherit; top: inherit; vertical-align: super; }
.md-reset { margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: top; background-color: transparent; text-decoration: none; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1rem; text-shadow: none; float: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; line-height: normal; font-weight: normal; text-align: left; box-sizing: content-box; direction: ltr; background-position: initial initial; background-repeat: initial initial; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li p, li .mathjax-block { margin: 0.5rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; }
@media print {
html, body { height: 100%; }
.typora-export * { -webkit-print-color-adjust: exact; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
a img, img a { cursor: pointer; }
#write pre.md-meta-block { font-size: 0.8rem; min-height: 2.86rem; white-space: pre; background-color: rgb(204, 204, 204); display: block; background-position: initial initial; background-repeat: initial initial; }
p > .md-image:only-child { display: inline-block; width: 100%; text-align: center; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.mathjax-block { white-space: pre; padding-bottom: 0.65rem; overflow: hidden; width: 100%; }
p + .mathjax-block { margin-top: -1.143rem; }
.mathjax-block:not(:empty)::after { display: none; }
[contenteditable="true"]:active, [contenteditable="true"]:focus { outline: none; box-shadow: none; }
:focus { outline: none; box-shadow: rgb(79, 172, 249) 0px 0px 2px 3px, rgb(120, 174, 218) 0px 0px 2px inset; }
.task-list { list-style-type: none; }
.task-list-item { position: relative; padding-left: 1em; }
.task-list-item input { position: absolute; top: 0px; left: 0px; }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-top-left-radius: 10px; border-top-right-radius: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc::after, .md-toc-content::after { display: none; }
.md-toc-item { display: block; color: rgb(65, 131, 196); text-decoration: none; }
.md-toc-inner:hover { text-decoration: underline; }
.md-toc-inner { display: inline-block; cursor: pointer; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: bold; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
.md-toc-h6 { margin-left: 12em; }
@media screen and (max-width: 48em) {
.md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
.md-toc-h4 .md-toc-inner { margin-left: 5em; }
.md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 { margin-left: 9.5em; }
}
a.md-toc-inner { color: inherit; font-size: inherit; font-style: inherit; font-weight: inherit; text-decoration: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.md-attr { display: none; }
.md-fn-count::after { content: '.'; }
.md-tag { opacity: 0.5; }
h1 .md-tag, h2 .md-tag, h3 .md-tag, h4 .md-tag, h5 .md-tag, h6 .md-tag { font-weight: initial; opacity: 0.35; }

html { font-size: 16px; }
html, body { background-color: rgb(243, 242, 238); font-family: 'PT Serif'; color: rgb(31, 9, 9); line-height: 1.5em; }
#write { max-width: 36em; }
ol, ul { list-style: none; }
blockquote, q { quotes: none; }
blockquote::before, blockquote::after, q::before, q::after { content: none; }
table { border-collapse: collapse; border-spacing: 0px; }
h1, h2, h3, h4, h5, h6 { font-weight: bold; }
h1 { font-size: 1.875em; line-height: 1.6em; margin-top: 2em; }
h2, h3 { font-size: 1.3125em; line-height: 1.15; margin-top: 2.285714em; margin-bottom: 1.15em; }
h3 { font-weight: normal; }
h4 { font-size: 1.125em; margin-top: 2.67em; }
h5, h6 { font-size: 1em; }
h1 { border-bottom-width: 1px; border-bottom-style: solid; margin-bottom: 1.875em; padding-bottom: 0.8125em; }
a { text-decoration: none; color: rgb(6, 85, 136); }
a:hover, a:active { text-decoration: underline; }
p, blockquote, pre.md-fences, .md-fences { margin-bottom: 1.5em; }
h1, h2, h3, h4, h5, h6 { margin-bottom: 1.5em; }
blockquote { font-style: italic; border-left-width: 5px; border-left-style: solid; margin-left: 2em; padding-left: 1em; }
ul, ol { margin: 0px 0px 1.5em 1.5em; }
ol li { list-style-type: decimal; list-style-position: outside; }
ul li { list-style-type: disc; list-style-position: outside; }
.md-meta, .md-before, .md-after { color: rgb(153, 153, 153); }
table { margin-bottom: 1.5em; font-size: 1em; }
thead th, tfoot th { padding: 0.25em 0.25em 0.25em 0.4em; text-transform: uppercase; }
th { text-align: left; }
td { vertical-align: top; padding: 0.25em 0.25em 0.25em 0.4em; }
code, pre.md-fences { background-color: rgb(218, 218, 218); padding-left: 1ch; padding-right: 1ch; }
pre.md-fences { margin-left: 2em; margin-bottom: 3em; }
pre, code, tt { font-size: 0.875em; line-height: 1.714285em; }
h1 { line-height: 1.3em; font-weight: normal; margin-bottom: 0.5em; }
p + ul, p + ol { margin-top: -1em; }
h3 + ul, h4 + ul, h5 + ul, h6 + ul, h3 + ol, h4 + ol, h5 + ol, h6 + ol { margin-top: 0.5em; }
li > ul, li > ol { margin-top: inherit; }
h2, h3 { margin-bottom: 0.75em; }
hr { border-style: none none solid; border-bottom-width: 1px; }
h1 { border-color: rgb(197, 197, 197); }
blockquote { border-color: rgb(186, 186, 186); color: rgb(101, 101, 101); }
thead.md-table-edit { background-color: transparent; }
thead { background-color: rgb(218, 218, 218); }
tr:nth-child(even) { background-color: rgb(232, 231, 231); background-position: initial initial; background-repeat: initial initial; }
hr { border-color: rgb(197, 197, 197); }
.task-list { padding-left: 1rem; }
.task-list-item { padding-left: 1.5rem; list-style-type: none; }
.task-list-item input::before { content: '√'; display: inline-block; width: 1.25rem; height: 1.5rem; vertical-align: middle; text-align: center; color: rgb(221, 221, 221); background-color: rgb(243, 242, 238); }
.task-list-item input:checked::before, .task-list-item input[checked]::before { color: inherit; }
#write pre.md-meta-block { min-height: 1.875rem; color: rgb(85, 85, 85); border: 0px; background-color: transparent; margin-left: 1em; margin-top: 1em; background-position: initial initial; background-repeat: initial initial; }
.md-image > .md-meta { color: rgb(155, 81, 70); }
.md-expand.md-image > .md-meta { background-color: rgba(255, 255, 255, 0.65098); }
.md-image > .md-meta { font-family: Menlo, 'Ubuntu Mono', Consolas, 'Courier New', 'Microsoft Yahei', 'Hiragino Sans GB', 'WenQuanYi Micro Hei', sans-serif; }
#write > h3.md-focus::before { left: -2.5rem; color: rgb(153, 153, 153); border-color: rgb(153, 153, 153); }
#write > h4.md-focus::before { left: -2.5rem; top: 0.25rem; color: rgb(153, 153, 153); border-color: rgb(153, 153, 153); }
#write > h5.md-focus::before { left: -2.5rem; color: rgb(153, 153, 153); border-color: rgb(153, 153, 153); }
#write > h6.md-focus::before { left: -2.5rem; top: 0.3125rem; color: rgb(153, 153, 153); border-color: rgb(153, 153, 153); }
.md-toc:focus .md-toc-content { margin-top: 19px; }
.md-toc-content:empty::before { color: rgb(6, 85, 136); }
.md-toc-item { color: rgb(6, 85, 136); }
#write div.md-toc-tooltip { background-color: rgb(243, 242, 238); }
#outline-dropmenu { background-color: rgb(243, 242, 238); -webkit-box-shadow: rgba(0, 0, 0, 0.372549) 0px 6px 12px; box-shadow: rgba(0, 0, 0, 0.372549) 0px 6px 12px; }
.pin-outline #outline-dropmenu { background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; box-shadow: none; border-right-width: 1px; border-right-style: dashed; background-position: inherit inherit; background-repeat: inherit inherit; }
.pin-outline #outline-dropmenu:hover .outline-title-wrapper { border-left-width: 1px; border-left-style: dashed; }
.outline-item:hover { background-color: rgb(218, 218, 218); border-left-width: 18px; border-left-style: solid; border-left-color: rgb(218, 218, 218); border-right-width: 18px; border-right-style: solid; border-right-color: rgb(218, 218, 218); }
.outline-expander::before { content: ''; font-family: FontAwesome; font-size: 14px; top: 1px; }
.outline-expander:hover::before, .outline-item-open > .outline-item > .outline-expander::before { content: ''; }

Moving Swiftly(从OC到swift)

31 Aug 2015

Last year, Apple revealed Swift, the future of software development on their platforms. Next Wednesday they’re expected to officially release Swift 2 as part of Xcode 7 GM. In just a year, everything has changed. We went from writing our apps in an object-oriented flavour of C, to writing almost exclusively Swift. I’m personally writing more code than I have in years, in part because it’s just fun.

Swift1.0 not fun

Now, to be clear, writing Swift 1.0 was not fun. It was novel, it was at times exciting, but it was not fun. The compiler would crash, the syntax highlighter would crash, the IDE would crash. The running app would surprisingly not crash, but that was pretty much the only non-crashing thing in the vicinity of any Swift 1.0 developer’s desk. I think this caused a bit of bad blood, and a number of folks who tested the Swift waters early promptly returned to the Objective-C they knew and loved.

While that was happening, Steamclock dug in. We started building internal tools with Swift last June. That October, we decided to start giving clients the option of going for Swift for new app builds. It seemed optimistic, but we were excited to level up our Swift experience and give new projects a leg up on the future. The results were blow-away: of roughly a dozen clients, only one opted for Objective-C. (这是爱不释手了吗?)Swift became our default programming language almost overnight.

Now, as the language is hitting its stride, we’re more productive, we’re seeing fewer issues in the field, and our clients are happy to be ahead of the curve. Almost as importantly, it’s fun - it sure makes recruiting easier when you’re hiring people to write Stack Overflow’s “most loved” language. (By the way, if you’re a Vancouver mobile developer who’d like to come write Swift at Steamclock, get in touch.)

Trouble

1.source compatibility代码兼容性

That’s not to say that the Swift transition didn’t cause some pain. For example, the explicit lack of source compatibility between versions is pants-on-head insane. At least, that’s what people say when they hear the term “no source compatibility between versions.”

In practice it’s not quite so bad. Lack of source compatibility means that each time a new version of Swift is released, you need to block out an hour to a day to migrate your code to it, after which point it will no longer run on the old version of Swift. In the common case that you’re not distributing your code that’s not so bad, but when you start dealing with Swift-based CocoaPods, it gets messy.

2.swift->Xcode->iOS 版本依赖

The bigger issue is that Swift versions are tied to Xcode versions, and Xcode versions are tied to iOS versions. So, if you want to debug your Swift app on an iOS 9 device, you need to use Xcode 7 beta, which only compiles Swift 2, which means you need to port your app to Swift 2 to debug it on iOS 9. Meanwhile, even this late in the game, you still can’t send betas to customers or reviewers from Xcode 7 beta, which means you can’t beta test Swift 2 apps, which means Testflight and Swift don’t go well together.

It’s clear they’re going to improve this little mess, though it’s unclear exactly when or how. Either Swift needs to start locking down some source compatibility, or Xcode and Swift need to be more decoupled. Either way, Testflight definitely needs to support external beta testing with beta versions of Xcode, because srsly.

All that said, we’ve successfully worked around it, mostly by relying less on Testflight and by avoiding the Xcode betas for projects that might need to be distributed to the App Store any time soon. It’s not ideal, but this dance been a worthwhile tradeoff for the benefits Swift gives us. It seems like the language is in a good enough place that future versions should require substantially less thrash, but are we out of the woods yet? It’s a bit hard to tell.

Salt in the wound伤口上撒盐

error reporting 错误提示

With Swift 2, the other issue I still regularly hit is quirky error reporting. Errors matter a lot in statically compiled languages, which ask a lot more of developers than a loose language does in terms of just getting the damn thing to run. Swift is more heavy-handed this way than Objective-C, due to its stricter mutability and optionality rules.

As such, writing Swift code that doesn’t compile is easy, especially when you’re learning. Luckily, a great compiler can have a nuanced enough understanding of your code to point out issues clearly and rapidly. Swift was designed to enable exactly this, via great autocompletion and expressive error messages.

Unfortunately, while the infrastructure for developing good errors was in place early on, initial versions of Swift tended to produce very misleading errors, even from simple typos. Even with 2.0, Xcode will give you the occasional self-referential error that really makes you wonder what exact strain of hallucinogen it has recently consumed.

错误提示改进swift2.0

Luckily, the errors are getting a lot better, and seem to be rightly recognized as a priority to the Xcode team. In many cases, Swift now gives better errors than were possible in Objective-C. For example, this code can’t compile because Swift won’t coerce Int to a String:

let number: Int = 1

let text: String = (number < 0) ? "" : number

For that code, in Swift 1.2 the error you would get was:

Could not find an overload for < that accepts the supplied arguments

Which is wacky, since “<” has nothing to do with the problem. I filed a Radar, and in Swift 2 the error is now much better:

Result values in ‘?:’ expression have mismatching types ‘String’ and ‘Int’

Which is exactly the problem and immediately clear. With that positive reinforcement, I and many others keep filing silly error Radars. The error messages keep getting better, and my affection for Swift grows.

In this way, the march of progress has been both steady and relentless. Swift 1.1 brought improvements to the Cocoa APIs to make them more Swift-friendly, tweaked and improved the language, and made Xcode more reliable and performant. Swift 1.2 brought more of the same. Swift 2.0 brought yet more. A year later, the annoyances and remaining issues feel small compared to benefits we’re getting, and it just keeps getting better.

Think about the good times好处呢?

Meanwhile, lot of smart people are still holding off on using Swift. I get the rationale – it was rough out of the gate, and learning a new language is a substantial undertaking. Swift is a bigger language than Objective-C or something like JavaScript, and it has a lot of depth. This is clear from the fact that other smart people are still theorizing and dissecting their experience of learning Swift, working to understand how best to use this new tool.

Yet as much as it may seem like work, this investment will pay off quickly. Basic Swift is very easy to write, and learning something new never goes out of style.

So I have a proposal to all you Objective-C developers out there. Next Wednesday, when the Xcode 7 GM delivers Swift 2 in its full shininess and, likely, open source goodness, jump in. Start something new. A side project, a game, a new view in your existing app - anything to get over the idea that you don’t know Swift. Something to get you addicted. Know that the fear of something big and new, the fear of losing what you know, the fear of “doing it wrong” at first, is natural. You’ve just gotta shake it off. Shake it off.

Moving Swiftly(从OC切换到Swift)的更多相关文章

  1. 记OC迁移至swift中笔记20tips

    写久了OC后来写swift,总感觉写着是swift的皮毛,但是实际上是OC的核心,这里整理了OC迁移至swift中的一些小细节. 1 在当前类中,实例方法调用属性以及方法都可以将self省略掉,而且是 ...

  2. iOS OC中桥接swift第三方库

    swift中有一些比较好的框架,比如绘图框架charts,最近项目中刚好用到,通过Pod的方式直接导入,xcode会自动生成charts-swift.h的文件,然后在需要导入的地方import < ...

  3. OC项目加入swift第三方库遇到的坑

    https://www.jianshu.com/p/96d868dcd69c 2017.07.07 16:23* 字数 295 阅读 5218评论 2喜欢 4 首先,在OC项目的Podfile文件中添 ...

  4. iOS开发——混编Swift篇&OC移植为swift

    将Ojective-C代码移植转换为Swift代码 2015-03-09 15:07发布:yuhang浏览:201   相比于Objective-C,Swift语言更加简练.有时我们需要把原来写的一些 ...

  5. 在OC中调用Swift类中定义delegate出现:Property 'delegate' not found on object of type ...

    找了许久没找到答案, 在下面的链接中, 我解决了这个问题: http://stackoverflow.com/questions/26366082/cannot-access-property-of- ...

  6. OC工程调用Swift方法

    1.建一个OC工程命名为SwiftOC.如图所示: 2.新建一个swfit文件命名为Test.swift,会弹出提示,选择Create Bridging Header建立桥接文件,系统会建立“工程名- ...

  7. Swift基础之OC文件调用Swift代码(在上次的基础上写的)

    前两天刚写过Swift调用OC,今天在原来的基础上,实现OC调用Swift. 首先,创建一个OneSwiftFile.swift文件,创建一个继承于NSObject的类(这个地方你可以自己选择继承的父 ...

  8. 在 OC 中调用 Swift 代码

    1.在 Objective-C 项目中使用 Swift 代码 1)在 OC 项目中创建 .Swift 文件,文件中的格式为其本有的格式. 2)Xcode 提示是否创建 Objective-C brid ...

  9. 前言-关于学习OC还是学习Swift的个人理解

    一直在考虑一个问题!到底是学swift好呢还是学OC好. 然后得到了解答: 1.如果你只是对苹果系统软件开发有兴趣,把开发作为一种业务爱好,那么选swift就没错,swift也是大势所趋. 2.如果你 ...

随机推荐

  1. ArcGIS 10.2数字化线状要素时自己主动拼接成一条线

    一開始一直和捕捉和经典捕捉过不去.最后才发现找错了地方,原来要Customize.自己定义加入"Continue Feature"工具,将其拖动到界面上的随意工具条内就可以.如图1 ...

  2. Python 文件 close() 方法

    描述 Python 文件 close() 方法用于关闭一个已打开的文件.关闭后的文件不能再进行读写操作, 否则会触发 ValueError 错误. close() 方法允许调用多次. 当 file 对 ...

  3. python3 bytes 和 string转换

    转自:http://www.jb51.net/article/105064.htm 前言 Python 3 最重要的新特性大概要算是对文本和二进制数据作了更为清晰的区分. 文本总是 Unicode,由 ...

  4. 安装ganglia过程中出现错误 perl(RRDp) is needed by rrdtool-1.2.30-1.el5.rf.x86_64

    用rpm -ivh *.rpm安装ganglia的rpm包,然后出现下面的错误: warning: rrdtool-1.2.30-1.el5.rf.x86_64.rpm: Header V3 DSA/ ...

  5. Java 打印程序设计实例

    3.1 打印文本 3.1.1 应用场景 假设我们需要打印一个窗体的某个文本编辑域(可能只有几行,也可能包含多页)的内容,并且每页最多打印 54 行,如何实现呢? 3.1.2 解决方法 基本思路如下:首 ...

  6. 怎么部署 .NET Core Web项目 到linux

    .NET Core is free, open source, cross platform and runs basically everywhere. STEP 0 - GET A CHEAP H ...

  7. Tomcat7启动报Error listenerStart错误

    问题 Tomcat7在启动时报错,详细信息如下: 十一月 23, 2013 7:21:58 下午 org.apache.catalina.core.StandardContext startInter ...

  8. [转载]Cortana 设计指导方针

    来源:@微软中国MSDN,源地址:http://weibo.com/p/1001603898586285925224 使用语音命令,延伸 Cortana 与您的应用程序所提供的功能.启动应用程序,启动 ...

  9. 关于Java Webproject中web.xml文件

    提及Java Webproject中web.xml文件无人不知,无人不识,呵呵呵:系统首页.servlet.filter.listener和设置session过期时限.张口就来,但是你见过该文件里的e ...

  10. jQuery添加/改变/移除CSS类

    转自:http://www.jbxue.com/article/24589.html 在jquery中用到removeClass移除CSS类.addClass添加CSS类.toggleClass添加或 ...