Home  >  Q&A  >  body text

objective-c - 求教iOS开发知识

做iPhone/iPad需要哪些知识??

洒家只知道要会 Objective-c,
熟悉 iOS SDK
工具是 xcode

基础的 数据结构、算法、多线程、Socket、XML ,这些应该也是要掌握的,
还有些啥?

或者,能不能细化一下Objective-c的重要技术点?谢谢。。

黄舟黄舟2765 days ago410

reply all(4)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:32:24

    As a developer who switched to iOS development halfway, judging from my two months of development experience, Objective-C is not difficult at all. The program I developed has gone through the following changes, and I also took the opportunity to summarize the gains and losses

    The most retarded hello world

    Create a new project from xcode, then open the Window Editor (Interface Builder, IB for short), drag in a UILabel component, write "Hello World", and you're done.

    Understand the composition of code

    Although its name is "objective-c", it seems to be completely different from the C language I have written before. It is full of countless hidden rules that can confuse novices.

    1. Why use #import instead of #include?
    2. #import而不用#include?
    3. @property是什么东西?它括号里面的(strong, nonatomic)又会发生什么奇怪的化学反应?为什么我在@interface里声明了属性,还要再@property?它和@synthesize又有什么关系?

    这一阶段基本上集中了很多小白的问题,幸运的是这些问题都很容易在网上找到答案,而且如果你有其它的语言基础的话也会很容易理解这些语法。

    我在这一阶段写出的代码基本惨不忍睹,所有的代码都放在一个controller里,一个是因为我懒,另一个是因为我还没有掌握objective-c开发世界里的编码风格,所以索性就不要风格了。你的代码里可能充满了IBOutlet或者IBAction

    不过只要你的代码能够工作,那么一切都是值得的。

    初窥精髓

    在cocoa框架里的一大精髓就是delegate,中文翻译为"委托"模式(本人自创直译其为"代理"模式)。虽然这一模式并不是cocoa的独创,但也是它运用的最好的地方之一。delegate模式解决了controllerview之间的交互问题。

    在我写代码的时候,往往发现只要seDelegate,就会发生很多很美妙的事情。另外你会发现,ios提过的这些基本组件已经无法满足你对交互的要求了,这时候你可能需要开始扩展它的一些基本组件。

    扩展它的基本组件是件很简单的事情,sdk中也预留了很多接口供我们override。一般这时候的你看着以前自己写的丑陋的代码,会忍不住开始重构它,放手去重构吧。

    得心应手

    其实了解了objective-c What is @property? What strange chemical reactions will occur in the (strong, nonatomic) inside the brackets? Why am I in @interface If a property is declared in @property, what does it have to do with @synthesize?

  • This stage basically focuses on a lot of novice questions. Fortunately, the answers to these questions are easy to find online, and if you have other language foundations, it will be easy to understand these grammars. 🎜 🎜The code I wrote at this stage is basically terrible. All the code is placed in a controller. One is because I am lazy, and the other is because I have not mastered the coding style in the objective-c development world, so I simply No more style. Your code may be filled with IBOutlet or IBAction. 🎜 🎜But as long as your code works, it's all worth it. 🎜 🎜First glimpse into the essence🎜 🎜One of the essences of the Cocoa framework is delegate, which is translated into Chinese as "delegate" mode (my own literal translation is "agent" mode). Although this model is not original to Cocoa, it is also one of its best uses. The delegate pattern solves the interaction problem between controller and view. 🎜 🎜When I write code, I often find that as long as seDelegate is used, many wonderful things will happen. In addition, you will find that these basic components mentioned by iOS can no longer meet your interaction requirements. At this time, you may need to start extending some of its basic components. 🎜 🎜Extending its basic components is a very simple matter, and there are many interfaces reserved in the sdk for us to override. Usually at this time, when you look at the ugly code you wrote before, you can't help but start to refactor it. Let go and refactor it. 🎜 🎜Comfortable🎜 🎜In fact, after understanding some of the hidden rules of the objective-c world, in addition to mastering its API, it has basically become an ordinary tool language. 🎜

    But it should be noted that ARC, the automatic reference counting thing, was introduced after xcode 4, and it is turned on by default. It may cause you some trouble. Many beginners worry that letting the system manage memory will cause a waste of memory. In fact, after understanding its principle, they find that its implementation is very simple. In fact, when no one references an object, the system automatically releases it. dropped. Leaving it to the system can also avoid the formation of memory fragmentation, but if you need to frequently read and write memory in a memory area, such as a message queue implemented by yourself, it is recommended to implement it yourself through struct . release掉。而交给系统来处理也可以避免内存碎片的形成,但如果你需要频繁在一块内存区域读写内存,比如自己实现的消息队列之类的,建议自己通过struct来实现。

    但是如果你定义这样一个struct

    typedef struct _Test {
    
        NSString *name;
    
    } Test;

    编译器会无情的告诉你,在struct里无法引用objective-c的对象,为什么?因为ARC无法控制到struct里的引用计数。但是如果你非要在struct里引用一个对象怎么办,你可以使用void *来保存一个指针

    typedef struct _Test {
        void *namePtr;
    } Test;
    
    // malloc的指针也不会被arc, 注意自己释放
    Test test = (Test *)malloc(sizeof(Test));
    test.namePtr = (__bridge void *)[NSString stringWithString:@"Hello"];

    但有一个问题,在上面的代码中[NSString stringWithString:@"Hello"]这只是个临时变量,虽然它被struct的指针指向了,但是前面说到了,这不会引起ARC的引用计数。

    那么就是说ARC会认为没有人引用这个变量,如果不出意外,这段代码执行玩以后,这片内存会被系统回收。如果你再次调用这个指针指向的内存,只会得到一个EXC_BAD_ACCESS错误。

    解决方法其实很简单,我们可以强制让ARC计数,比如在当前的@interface

    But if you define such a struct

    @interface TestObj : NSObject {
        NSString *name;
    }
    
    - (void)initName
    {
        name = [NSString stringWithString:@"Hello"];    // 强制引用
        Test test = (Test *)malloc(sizeof(Test));
        test.namePtr = (__bridge void *)name;
    }

    The compiler will tell you mercilessly that objective-c objects cannot be referenced in struct. Why? Because ARC cannot control the reference count in the struct. But what if you have to reference an object in the struct? You can use void * to save a pointer#🎜🎜# rrreee #🎜🎜#But there is a problem. In the above code, [NSString stringWithString:@"Hello"] is just a temporary variable. Although it is pointed to by the pointer of struct, as mentioned before, This does not cause ARC's reference counting. #🎜🎜# #🎜🎜#That means ARC will think that no one refers to this variable. If nothing else happens, after this code is executed, this memory will be reclaimed by the system. If you call the memory pointed to by this pointer again, you will only get an EXC_BAD_ACCESS error. #🎜🎜# #🎜🎜#The solution is actually very simple. We can force ARC to count, for example, set a variable in the current @interface to point to this string so that it will not be released#🎜🎜# rrreee #🎜🎜#OK, it’s a bit messy after talking so much, and finally I complained about ARC. The final conclusion is that it is quick to get started, but you also need to study on your own to learn it well. #🎜🎜#

    reply
    0
  • 阿神

    阿神2017-04-17 17:32:24

    The first level: objective-c syntax can be practiced successfully in three days
    Second layer: migrant worker UI: usage of UIView, UILabel, UIImageView, UITableView, UINavigationController, and UITabBarViewController. It takes one to two months to practice depending on your qualifications.
    The third layer: various functional APIs: network request, persistence, address book, GPS, email API, and various APIs. Half a year
    The fourth layer: UI advancement: rotating screen, core animation, custom drawing view, drawing context, etc. Half a year
    Level 5: Advanced skills: runtime, cocos, OpenGLES, etc. The practice has not yet been completed and the required date is not yet known.

    reply
    0
  • PHPz

    PHPz2017-04-17 17:32:24

    Suggestion 1, don’t study systematically
    Suggestion 2, start by writing Hello World, write apps one by one, and learn what you use
    Suggestion 3. No book on the market is reliable
    Suggestion 4, read official documents and sample code

    reply
    0
  • 黄舟

    黄舟2017-04-17 17:32:24

    A picture will tell you! Please read the article: http://www.henishuo.com/ios-study-route/

    reply
    0
  • Cancelreply