Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.pcisys.net!news.pcisys.net.POSTED!not-for-mail NNTP-Posting-Date: Fri, 12 Aug 2011 11:46:21 -0500 From: Tom Harrington Newsgroups: comp.lang.objective-c Subject: Re: Instance Method Declaration Optional? Organization: Atomic Bird References: <0cda4b2f-239d-445f-acf7-ab75c65b8c7e@a17g2000yqk.googlegroups.com> User-Agent: MT-NewsWatcher/3.5.1 (Intel Mac OS X) Date: Fri, 12 Aug 2011 10:46:20 -0600 Message-ID: Lines: 39 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-bvzq8VeNZXOMFUFUzp7ZYROTe9h1eA41T7WrMZ1ZDSSmAJPfBqUenwEc6dNp0sX66mDaDY3SOS+B9t5!DMsaZYoCOmv9bJUlOtcCtxie+ePp9iixn6pbg6CTiFaejAie0B9MFbYb0FsBaoxlc+e9JDz4ii+L!hLc6JQ== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2804 Xref: x330-a1.tempe.blueboxinc.net comp.lang.objective-c:27 In article <0cda4b2f-239d-445f-acf7-ab75c65b8c7e@a17g2000yqk.googlegroups.com>, PhilG wrote: > Hello, > > I implemented the Notifications example in the Conway and Hillegass > _iPhone Programming_ book, Ch. 9, and the selector passed to > addObserver:selector:name:object is defined in the implementation of > the application delegate but is not declared either in its interface > or its superclasses or protocols. Okay, that seemed odd so I added > another arbitrarily named method to respond to proximity change > notifications. I defined the function in the implementation but, > again, did not declare it in the interface. The program compiled and > ran flawlessly. What gives? Are instance method declarations optional > in this case? In the first case, when adding notification observers, you're passing in a selector but not actually calling the method right away. Whether the method the selector refers to is declared doesn't really matter at compile time. The notification center will locate the method dynamically at run time. In the second case, the compiler needs to know about a method before you attempt to call it. That's the whole purpose of the method declaration-- to tell the compiler about a method that it has not actually seen yet. That means that either (a) you need to provide a method declaration, or (b) the method implementation needs to be in the same source file as the call AND must appear earlier in the file than the call. I can't tell from your description if you added code to call the new method. If you did, your method call must have been later in the file than the implementation. If the order were reversed, you'd need to provide a declaration. -- Tom "Tom" Harrington Independent Mac OS X developer since 2002 http://www.atomicbird.com/