Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Torchi12

macrumors newbie
Original poster
Oct 2, 2011
6
0
1.
Watched a tutorial about substrings.
Here is some code:
Code:
NSString *d = @"Dont feed grapes to dogs!";

NSRange range = [d rangeOfString:@"grapes"];
Now, my question is, why is the NSString object a pointer but not the NSRange object?

2.
I don't quite understand static, could someone try to explain?

3.
When I make a new file, it automatically adds the following:
Code:
#import "testLolIgnoreMe.h"


@implementation testLolIgnoreMe

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    
    return self;
}

- (void)dealloc
{
    [super dealloc];
}
//and other methods u create yourself
@end

Should it always look like that? With that init, and dealloc?
The way I've learnt Obj c is just simply

Code:
#import <Foundation/Foundation.h>
#import "FakeClass.h"

int main(int argc, const char* argv[])
{
NSAutoreleasePool *pool = [ [NSAutoreleasePool alloc] init];

FakeClass *object = [ [FakeClass alloc] init];

//do some stuff

[object release];
[pool drain];

return 0;
}
Is my way wrong, outdated or something?
Should I start doing it like the example code? The one that shows up when i create a new file?

4.
About objects, I do it by doing = [ [Class alloc] init ];
But I've seen other ways, like autorelease.
Should I continue with alloc, init?

5.
Autoreleasepools are only used when u initialize objects with autorelease?
And send a release message to all obejcts that use autorelease?
Something like that? Read it somewhere, always understand better when people explain to me though.
 
Too many questions which would each require an essay because you're lacking fundamental understandings.

I suggest you start reading good material instead of watching tutorials. If you aren't willing or able to get your hands on a book, then start reading the Apple documentation.

http://developer.apple.com/library/mac

Read the documents under the Getting Started tab. Then move on to the documents under the Required Reading tab.
 
Something like that? Read it somewhere, always understand better when people explain to me though.

Instead of trying to get it on the internet for free, why don't you try to hire someone to give you lessons? That's how I made a bit of money when I was sixteen; you should have no problem finding someone who will give you lessons for $15 or $20 an hour.
 
Instead of trying to get it on the internet for free, why don't you try to hire someone to give you lessons? That's how I made a bit of money when I was sixteen; you should have no problem finding someone who will give you lessons for $15 or $20 an hour.

I'd love someone to give me lessons maybe over webcam or something. Any one know where to look?
 
1.*NSString is here:
http://developer.apple.com/library/...lasses/NSString_Class/Reference/NSString.html
NSRange is here:
http://developer.apple.com/library/...oundation_DataTypes/Reference/reference.html*
They are different sorts of things. Start your research there for immediate answers, but head here for more of a foundation:
http://developer.apple.com/library/mac/documentation/cocoa/conceptual/objectivec/objc.pdf

2. This means different things in different contexts. In a class declaration context this means the variable is a class member variable, so whenever this variable is referenced at the class level or from an instance method, the exact same variable is used. This is for storing class-level state, such as a pointer to a singleton instance.
In a plain C function this means that the variable lives on the heap, and the variable has program lifetime. It will persist across invocations, contrasting with automatic, stack-local variables, the "normal" case.

3. This is the difference between a barebones class implementation file and a basic entry point to a program. main is the entry point to all C and Objective-C programs. As others have noted, this is as basic as it comes. What docs have you read so far?

4. Read the memory management programming guide:
http://developer.apple.com/library/...onceptual/MemoryMgmt/Articles/MemoryMgmt.html
It will tell you about retain, release, and autorelease. It will explain ownership, if you own an object returned from a method with init in the name, and lots of other critical pieces of information.

5. Read the guide from step 4 again. You'll need to at least twice, anyway. It's that important. You always need an autorelease pool. Even if you don't send a single autorelease, code you're calling will. The specifics of when autoreleased objects get released isn't important, ownership is.

-Lee
 
Lifetime is correct. Storage class isn't.

A static variable has static storage class, never heap.

Which may or may not just be a difference in vocabulary, as some compiler/linker-loader/runtime combinations allocate C static storage class memory from the heap, before linking it to a runtime global base pointer.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.