Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read apple iOS documentation correctly? [closed]

I was following a tutorial I found on the web, there was line of code like this:

var myImage = UIImage(named: "icon")

I understand what this line does, but I don't want to memorize it of course, I want to understand how the author came up with this code, so I search the documentation for UIImage class reference, there is nothing under the initializers section that identify this code, so why? Where can I find more about this code?

I read a lot of tutorials I found on the web, watched a lot of video tutorials, and read a lot of books, ALL of them with no exceptions they show you the code, they fully explain it, BUT they don't tell you how they came up with it, how did they find the right method for the right job?

Should I spend my time reading Apple documentation instead of all these tutorials? Is there something I'm doing wrong? Am I missing something? I don't want to memorize all the stuff I read, that's not why I wanted to learn developing apps, I want to understand where to look to find the right code, I want to learn to think like a developer.

like image 863
Isaac Majdi Avatar asked May 13 '15 09:05

Isaac Majdi


People also ask

How do I view Apple documents?

In many apps, your Mac can read aloud documents, web pages, messages and more. In an app on your Mac, do any of the following: Hear an entire document: Choose Edit > Speech > Start Speaking. Hear part of a document: In a document, select the text you want to hear, then choose Edit > Speech > Start Speaking.

How do I write documents in Xcode?

Xcode provides an easy way to generate documentation. To use this feature, click on any class, property, function, or part you want to add a document. Then press ⌥ – Option + ⌘ - command + / or Editor > Structure > Add documentation from Xcode's menu. Xcode will generate a document template for you.


1 Answers

There are 3 useful sources of written information:

  1. Example code/Tutorials:

    The official documentation is great once you have some experience coding in Xcode/iOS, but it is a hard place to start. Nothing beats looking at good sample code.

    Example code (from Apple, from Stack Overflow, from Ray Wenderlich, from anywhere you can find it) is a great way to learn. Even people writing the tutorials you are reading started with other people's sample code. The first people learning iOS started with sample code from Apple.

  2. The official documentation:

    To get the the official documentation optionclick on UIImage in your code or in the Playground. In the pop up, select UIImage Class Reference. The initializer you are looking for is there:

    + imageNamed:
    Returns the image object associated with the specified filename.

    Declaration
    SWIFT
    init?(named name: String) -> UIImage

    OBJECTIVE-C
    + (UIImage *)imageNamed:(NSString *)name

    Parameters
    name The name of the file. If this is the first time the image is being loaded, the method looks for an image with the specified name in the application’s main bundle.

    Return Value The image object for the specified file, or nil if the method could not find the specified image.

    In Swift, of course, you don't call initializers directly by calling init. Instead, you use the class name, UIImage in this case. name is the internal name of the parameter, and the ? tells you this is a failable initializer that might return nil, so in fact this initializer returns a UIImage?. So you should look at init?(named name: String) -> UIImage and think UIImage(named: String) -> UIImage?.

  3. The header files:

    Type UIImage into your code or a Playground and Command-click on it. That will bring up the header file information for UIImage. The very first initializer listed is:

    init?(named name: String) -> UIImage // load from main bundle
    

You can learn a lot from reading the headers. I recommend checking them frequently.

like image 137
vacawama Avatar answered Oct 26 '22 13:10

vacawama