- 浏览: 340144 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
leslie89757:
[img][img][img][img][img][img][ ...
CocoaPods 安装使用 -
hanmeizhi:
very useful to me. Thanks
Dismissing MPMoviePlayerViewController the right way -
luzj:
这个考虑不周全, 在iOS5的键盘高度就不是这个值了,这样写死 ...
UITextView: move view when keyboard appears -
xjg19870111:
不错。
objective-c NSString 常用操作 -
juedui0769:
现在已经不行了!
android源码下载
Original Link: http://stuartkhall.com/posts/ios-development-tips-i-would-want-if-i-was-starting-out-today
iOS Development Tips I Would Want If I Was Starting Out Today
Making iOS apps is getting easier and easier with each new release of Xcode. However, all the new features and approaches means there are more options to choose from, outdated books and old documentation.
Back in my day it was so much harder - that's is true in many respects, but a much higher level of quality and features is expected now. The bar keeps rising, and that's a very good thing.
If I was starting out with iOS development today these are the things I would hope somebody would tell me.
Use ARC!
ARC is awesome, it removes a lot of the complexity of memory management we had to deal with previously. Although it's valuable to understand memory management, ARC makes life a whole lot easier.
As a (still) recovering C++ developer from many years ago, I fought it for quite a while. Also many popular libraries have gone ARC only, so don't fight it, go with it.
Prefer Blocks Where Possible
Blocks are awesome. They mean you write less code and clearer code.
There is a great tutorial on blocks here.
There are still times when delegates/protocols or NSNotifications make sense, but blocks should be your first consideration.
Beware Of Retain Cycles With Blocks
This can be nasty, rather than go into the details here check out this link.
Forget Threads, Use GCD
"A programmer had a problem, so he used threads, then he had two"
GCD has made life a lot easier, just don't forget to switch back to the main thread before doing anything with the UI:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
// Your code
dispatch_async(dispatch_get_main_queue(), ^(void) {
// Now you can interact with the UI
});
});
There is a good explanation of GCD, including making your own queues, here.
Singletons / Shared Objects
Carrying on with GCD, dispatch_once is really useful:
+ (MyClass *)sharedClass {
static MyClass *_shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_shared = [[MyClass alloc] init];
});
return _shared;
}
You'll be doing this a bit, especially when you see how costly it is to create things like NSDateFormatter many times.
Story Boards Are Just For Rapid Prototypes
In my opinion they are more pain than they are worth once you move beyond a basic project. Purely my opinion, some people love them. Make your own mind up on this one.
Only Use XIBs For Very Basic Layouts
There is so much you can't do in Interface Builder (IB). Any slightly "non standard" app with custom views move beyond IB's capabilities quickly. Still, I do use .xib's sometimes for the initial basic layouts, but I've read many people don't bother at all.
XIB's can also be a pain with source control and merging, it's much easier to merge code.
Keep Your Project Organised
I've done a bit of Ruby on Rails development and quite like the way they organise a project, so I do something similar in Xcode:
However you do it, try and keep it in some sort of order, it will get out of hand pretty quickly.
Embrace Open Source
There are so many amazing libraries and components available for iOS development. Github is full of great source code that you can just drop into your project, you can also use sites like Cocoa Controls to find components.
Some libraries I use in almost every project include:
AFNetworking - Block based networking library, so easy to use and so powerful.
RegexKitLite - Powerful regular expression support
Facebook iOS SDK - Facebook support
If you Google for a component you need chances are there is one out there to at least get you started.
Dependency Management
With all these great open source components you'll need a way to manage them. CocoaPods has done an amazing job at making something similar to Ruby's gems. Otherwise you can just use git submodules.
Learn To Love Stack Overflow
There are a lot of really smart iOS developers on Stack Overflow, and chances are they have solved your current issue. Please search before asking a question, more often than not it has been answered before.
Graceful Degradation
Often you want to use functionality from a new version of iOS, but you also need to support older versions. There are many examples of this, Tweet Sheets in iOS 5, SKStoreProductViewController & UIActivityViewController in iOS 6, there are many examples.
Luckily at run time you can check if the class exists and fall back (or just throw up an unsupported message).
if (NSClassFromString(@"SKStoreProductViewController")) {
// Class is supported, iOS 6+
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
….
}
else {
// Not iOS 6
}
Custom Fonts
In early iOS versions (pre 3.2) this was a nightmare, so everyone just used Helvetica. Luckily now it's simple!
Here is a quick guide. If you get stuck with the name of the font open up Font Book and look for the PostScript name.
Localize From The Start
Localization is pretty easy to do in Xcode, especially if you avoid xibs. But add localization support from the start of your project, it's a long painful experience to extract them later.
Here is a great guide to localizing an iPhone app.
Track Crashes
Crash logs are a pain, a real pain. Use a service that captures and symbolicates them for you. Two great services are HockeyApp and TestFlight
Analyze
Product -> Analyze can pick up a lot of potential issues (and a lot of red herrings).
Instruments
Product -> Profile builds your code and launches Instruments. Instruments is a collection of invaluable tools to profile your app. First stop should be "Time Profiler" where you can see what is eating the CPU in your app. If you want to get your table view scrolling like butter you will be spending a lot of time in here.
Track Reviews
<shameless self promotion>You'll have bugs, and people will write bad reviews in countries you may never heard of. Get them in your inbox daily with AppBot. </shameless self promotion>
I'm sure I've forgotten a bunch of things and not everyone will agree with everything above. Hopefully it will be useful to at least a few people just starting out in iOS development.
iOS Development Tips I Would Want If I Was Starting Out Today
Making iOS apps is getting easier and easier with each new release of Xcode. However, all the new features and approaches means there are more options to choose from, outdated books and old documentation.
Back in my day it was so much harder - that's is true in many respects, but a much higher level of quality and features is expected now. The bar keeps rising, and that's a very good thing.
If I was starting out with iOS development today these are the things I would hope somebody would tell me.
Use ARC!
ARC is awesome, it removes a lot of the complexity of memory management we had to deal with previously. Although it's valuable to understand memory management, ARC makes life a whole lot easier.
As a (still) recovering C++ developer from many years ago, I fought it for quite a while. Also many popular libraries have gone ARC only, so don't fight it, go with it.
Prefer Blocks Where Possible
Blocks are awesome. They mean you write less code and clearer code.
There is a great tutorial on blocks here.
There are still times when delegates/protocols or NSNotifications make sense, but blocks should be your first consideration.
Beware Of Retain Cycles With Blocks
This can be nasty, rather than go into the details here check out this link.
Forget Threads, Use GCD
"A programmer had a problem, so he used threads, then he had two"
GCD has made life a lot easier, just don't forget to switch back to the main thread before doing anything with the UI:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
// Your code
dispatch_async(dispatch_get_main_queue(), ^(void) {
// Now you can interact with the UI
});
});
There is a good explanation of GCD, including making your own queues, here.
Singletons / Shared Objects
Carrying on with GCD, dispatch_once is really useful:
+ (MyClass *)sharedClass {
static MyClass *_shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_shared = [[MyClass alloc] init];
});
return _shared;
}
You'll be doing this a bit, especially when you see how costly it is to create things like NSDateFormatter many times.
Story Boards Are Just For Rapid Prototypes
In my opinion they are more pain than they are worth once you move beyond a basic project. Purely my opinion, some people love them. Make your own mind up on this one.
Only Use XIBs For Very Basic Layouts
There is so much you can't do in Interface Builder (IB). Any slightly "non standard" app with custom views move beyond IB's capabilities quickly. Still, I do use .xib's sometimes for the initial basic layouts, but I've read many people don't bother at all.
XIB's can also be a pain with source control and merging, it's much easier to merge code.
Keep Your Project Organised
I've done a bit of Ruby on Rails development and quite like the way they organise a project, so I do something similar in Xcode:
However you do it, try and keep it in some sort of order, it will get out of hand pretty quickly.
Embrace Open Source
There are so many amazing libraries and components available for iOS development. Github is full of great source code that you can just drop into your project, you can also use sites like Cocoa Controls to find components.
Some libraries I use in almost every project include:
AFNetworking - Block based networking library, so easy to use and so powerful.
RegexKitLite - Powerful regular expression support
Facebook iOS SDK - Facebook support
If you Google for a component you need chances are there is one out there to at least get you started.
Dependency Management
With all these great open source components you'll need a way to manage them. CocoaPods has done an amazing job at making something similar to Ruby's gems. Otherwise you can just use git submodules.
Learn To Love Stack Overflow
There are a lot of really smart iOS developers on Stack Overflow, and chances are they have solved your current issue. Please search before asking a question, more often than not it has been answered before.
Graceful Degradation
Often you want to use functionality from a new version of iOS, but you also need to support older versions. There are many examples of this, Tweet Sheets in iOS 5, SKStoreProductViewController & UIActivityViewController in iOS 6, there are many examples.
Luckily at run time you can check if the class exists and fall back (or just throw up an unsupported message).
if (NSClassFromString(@"SKStoreProductViewController")) {
// Class is supported, iOS 6+
SKStoreProductViewController *storeController = [[SKStoreProductViewController alloc] init];
….
}
else {
// Not iOS 6
}
Custom Fonts
In early iOS versions (pre 3.2) this was a nightmare, so everyone just used Helvetica. Luckily now it's simple!
Here is a quick guide. If you get stuck with the name of the font open up Font Book and look for the PostScript name.
Localize From The Start
Localization is pretty easy to do in Xcode, especially if you avoid xibs. But add localization support from the start of your project, it's a long painful experience to extract them later.
Here is a great guide to localizing an iPhone app.
Track Crashes
Crash logs are a pain, a real pain. Use a service that captures and symbolicates them for you. Two great services are HockeyApp and TestFlight
Analyze
Product -> Analyze can pick up a lot of potential issues (and a lot of red herrings).
Instruments
Product -> Profile builds your code and launches Instruments. Instruments is a collection of invaluable tools to profile your app. First stop should be "Time Profiler" where you can see what is eating the CPU in your app. If you want to get your table view scrolling like butter you will be spending a lot of time in here.
Track Reviews
<shameless self promotion>You'll have bugs, and people will write bad reviews in countries you may never heard of. Get them in your inbox daily with AppBot. </shameless self promotion>
I'm sure I've forgotten a bunch of things and not everyone will agree with everything above. Hopefully it will be useful to at least a few people just starting out in iOS development.
发表评论
-
IOS7.1 企业应用 证书无效 已解决
2014-05-10 10:53 774http://www.cocoachina.com/bbs/r ... -
xCode Find&Replace快捷键
2013-10-28 10:44 907As for Find & Replace, they ... -
iOS整合zxing需要注意的地方
2013-08-02 23:34 2106Well, at last I got it working. ... -
iOS 自定义Tabbar
2013-07-30 22:55 1191http://www.appcoda.com/ios-prog ... -
Apple Push Notification Service总结
2013-07-29 22:39 1115苹果推送通知服务使用总结 1. 在 Mac 上从 KeyCha ... -
iOS 消息推送原理及实现
2013-07-12 13:40 855链接: http://www.dapps.net/dev/ ... -
GIMP IMAGE MAP
2013-05-29 16:13 853使用GIMP 制作 IMAGE MAP 1. 选择图片,用G ... -
INSPIRATION
2013-05-27 18:21 812http://www.patternsofdesign.co. ... -
iOS 自定义控件系列
2013-05-27 17:09 1480iOS自定义控件 自定义UITableViewCell ht ... -
CocoaPods 使用教程
2013-05-27 14:49 768http://mobile.tutsplus.com/tuto ... -
IOS 开发之设置UIButton的title
2013-05-11 22:03 1207btn.frame = CGRectMake(x, y, wi ... -
REActivityViewController 使用 备忘
2013-04-22 21:38 1058REActivityViewController Out o ... -
VPS配置二级域名
2013-04-18 23:08 7881. 域名解析商配置泛解析 主机记录 * 记录类型 A 2. ... -
ios 开发NewsStand指南
2013-04-13 21:44 1324http://www.viggiosoft.com/blog/ ... -
Python Django mod_wsgi Windows 部署过程 备忘
2013-04-10 18:28 1587部署环境:Windows2003Server 1. 安装Ap ... -
网站迁移 备忘
2013-04-10 14:58 7511. 备份数据库。。。导出的格式和编码要注意 2. 完全导出网 ... -
Windows下命令行查看端口占用
2013-04-09 23:42 723在windows命令行窗口下执行: C:\>netst ... -
带预览功能又可分页的UIScrollView
2013-04-05 12:56 823带预览功能又可分页的UIScrollView http:// ... -
25 iOS App 性能优化
2013-04-05 10:51 695http://www.raywenderlich.com/ ... -
UIScrollView滚动, 中间显示整图, 前后露出部分图
2013-04-04 00:12 1200UIScrollView *scrollowView = [[ ...
相关推荐
Using this book’s straightforward, step-by-step approach, you’ll master every skill and technology you need, from setting up your iOS development environment to building great user interfaces, ...
The update to the bestselling More iPhone Development by Dave Mark and Jeff LaMarche, More iPhone Development with Swift digs deeper into the new Apple Swift programming language and iOS 8 SDK, ...
App Development Recipes for iOS and watchOS explores the technical side of app development with tips and tricks to avoid those little things that become big frustrations, outside of the realm of ...
App Development Recipes for iOS and watchOS explores the technical side of app development with tips and tricks to avoid those little things that become big frustrations, outside of the realm of ...
C language to entire classes you might not have thought about using, everybody is sure to take away practical and useful tips and tricks to make developing iOS apps easier and more productive.
iOS 7 Game Development (pdf书及源代码) Dmitry Volevodz, "iOS 7 Game Development" English | ISBN: 1783551577 | 2014 | 112 pages | PDF What you will learn from this book Create and run your own ...
•Full of useful tips and techniques to help you become an iOS pro What You’ll Learn •Everything you need to know to develop your own best-selling iPhone and iPad apps •Best practices for ...
In this book, you will learn SpriteBuilder...Along the way, I’ll explain the SpriteBuilder features, caveats, workarounds, and helpful tips and tricks as you are most likely to come across or need them.
Combining practical steps with detailed insights, this book will help you discover and learn a powerful approach to game development to create exceptional iOS games, tips to create cool content, and ...
《使用cocos2d与iOS 5学习游戏开发》是一本深入浅出的教程,旨在教授读者如何利用cocos2d引擎在iOS平台上构建2D游戏。本书涵盖了从基础概念到高级技巧的全面内容,适合从初学者到有经验的游戏开发者。 ### 一、...
by-step guide to learning all aspects of creating a CareKit iOS application that could serve as the basis for a patient care plan.Beginning Carekit Development introduces the key modules and concepts...
If you are looking to extend your iOS programming skills beyond the basics then More iPhone Development with Objective-C is for you. Authors Dave Mark, Jayant Varma, Jeff LaMarche, Alex Horovitz, and ...
In this follow up work to the best-selling Beginning iPhone Development with Swift, you’ll learn tips for organizing and debugging Swift code, using multi-threaded programming with Grand Central ...
**PhoneGap 3.x Mobile Application Development Hotshot.2014.pdf** is a comprehensive guide designed to help developers create engaging and practical mobile applications for iOS and Android devices ...
- **John Muchow(创始人,iPhone Developer Tips.com;首席技术官,3Sixty Software)**:高度推荐本书作为学习 iPhone 开发的坚实基础。 #### 四、总结 《iPhone SDK 开发:构建 iPhone 应用程序》不仅是一本...
In just 24 lessons of one hour or less, learn how to start using Unreal Engine 4 to build amazing games for Windows, Mac, PS4, Xbox One, iOS, Android, the web, Linux–or all of them! Sams Teach ...