Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.objective-c > #198

Re: Objective C program doesn't compile

From "Pascal J. Bourguignon" <pjb@informatimago.com>
Newsgroups comp.lang.objective-c
Subject Re: Objective C program doesn't compile
Date 2015-11-11 19:45 +0100
Organization Informatimago
Message-ID <874mgs4boe.fsf@kuiper.lan.informatimago.com> (permalink)
References <a5d7b3bf-a215-4dbf-9888-dafcd52fba9f@googlegroups.com> <n1v492$up$1@dont-email.me> <96948669-edd2-4771-8e2a-18088313c98b@googlegroups.com>

Show all headers | View raw


modelling.data@gmail.com writes:

> <snip>
> Don, thank you very much for your reply.
>
> Indeed, I have been told a few times at C group that this book is garbage based
> on the code I post from it. I am frustrated now, and have no idea which textbook
> to pick up both for C and Objective-C. 

Well, a very important book for C would be:

   http://www.amazon.com/gp/product/0201179288?keywords=C%20Traps%20and%20Pitfalls&qid=1447266520&ref_=sr_1_1&sr=8-1

Sorry, I can't advise specifically a good C introductory book.  I would
hope that any of the most recent C books (covering at least c99, if not
c11), would teach good C.  Be careful not to chose a book covering C++
or worse, confusing C with C++.

Similarly, for Objective-C, I learned with the original Objective-C book,
http://www.amazon.com/Object-Oriented-Programming-An-Evolutionary-Approach/dp/0201548348
but Objective-C has evolved a little since, so you might prefer to read
more recent material, notably from Apple.


> The only thing which I did grab from it, as you mentioned, is the distinction
> between class and instance, but that, I believe, is the easiest and trivial 
> thing.
>
> I would be grateful for your advice on how to do it the right way - where
> shall I read about it? I know there are many sources on the net, but I picked up
> this Kochan's one because CS50 course advises it; and now all professionals, 
> including you, tell me that the stuff is garbage. I am brand new to
> programming, and I am learning on my own asking for help on these two groups.

There's nothing wrong fundamentally with your use of +new. It's just
that it was a method that existed in the Object class which was the
(implicit) root of the class hierarchy in older Objective-C.

Nowadays, the Object class is drastically reduced, since it's often
replaced anyways by some other class, such as NSObject.

You can check the header for the Object class. On linux it could be
somewhere like:

/usr/lib/gcc/x86_64-linux-gnu/4.9/include/objc/Object.h

On MacOSX it would be:

/usr/include/objc/Object.h


You can compare them, the gcc class only has:

    @interface Object
    {
      Class isa; /* A pointer to the instance's class structure.  */
    }
    - (Class)class;
    - (BOOL)isEqual: (id)anObject;
    @end

https://gcc.gnu.org/onlinedocs/gcc/Objective-C.html

while MacOSX provides a more complete Object class, including a +new
method.


In any case, you can implement it yourself:

   +(id)new{ return [[self alloc] init]; }

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html
http://readwrite.com/2011/05/14/4-free-e-books-on-objective-c


-- 
__NSObject Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

Back to comp.lang.objective-c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Objective C program doesn't compile modelling.data@gmail.com - 2015-11-10 23:32 -0800
  Re: Objective C program doesn't compile Don Bruder <dakidd@sonic.net> - 2015-11-11 02:14 -0800
    Re: Objective C program doesn't compile modelling.data@gmail.com - 2015-11-11 06:29 -0800
      Re: Objective C program doesn't compile Don Bruder <dakidd@sonic.net> - 2015-11-11 09:04 -0800
      Re: Objective C program doesn't compile "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-11 19:45 +0100
  Re: Objective C program doesn't compile "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-11 21:03 +0100
    Re: Objective C program doesn't compile modelling.data@gmail.com - 2015-11-13 08:19 -0800

csiph-web