Re: new to Cocoa/Objective-c: many points of confusion

2013-02-12 Thread Gavin Eadie
On Jan 22, 2013, at 1:10 AM, Alex Hall  wrote:

> I understand the concepts of modern programming (methods, classes, objects, 
> inheritance, all that) quite well thanks to that degree, but we never delved 
> much into C-style languages. Now, I am trying to teach myself Objective-c, 
> with the goal of writing some Mac and/or iOS apps (Mac ones first). I should 
> also say that I am blind, relying on Apple's Voiceover screen reader to use 
> my mac and iPhone.

Alex .. Welcome to the Objective-C list.  It's a good, though voluminous, list 
with many helpful participants.

When I read your email, I immediately thought you would benefit from Paul 
Hegarty's class on iTunes U:

  "Coding Together: Developing Apps for iPhone and iPad (Winter 2013)"
  https://itunes.apple.com/us/course/coding-together-developing/id593208016

Paul's course has been given in past years, but this (Winter 2013) course is 
better.  Only the first four lectures are on iTunes so far, but those are the 
ones you need.  I think the lectures could followed by someone without sight, 
particularly since it's the concepts you need to know about.

What caught my attention in the latest version of the course is that Paul has 
taken a slight different approach to introducing Objective-C and, very 
important, the model-view-controller (MVC) design pattern.  Objective-C has 
it's unique features and Paul covers those well.  Your understanding of 
"concepts of modern programming (methods, classes, objects, inheritance, all 
that)" is a great foundation, but these first few lectures will carry from 
those generalities to Objective-C specifics.

I've been programming for more than forty years and have accumulated all sorts 
of notions about programming from when learned and used C, Java, FORTRAN, IBM 
Assembler, etc, and even though I been using Objective-C for a few years, 
Paul's course made me realize that I'd been programming in Objective-C as if it 
was Java.  That isn't "wrong" (my programs work correctly) but it means I was 
missing out on some nifty Objective-C power.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to Cocoa/Objective-c: many points of confusion

2013-02-04 Thread Lee Ann Rucker

On Jan 21, 2013, at 10:10 PM, Alex Hall wrote:

> Hello all,
> 
> 
> *Outlets: I have a basic idea that these are a way of sending messages from 
> object to object, a bit like listeners. However, I don't really understand 
> the syntax used to make them. Moreover, I always see them used in GUIs, but 
> Xcode's Interface Builder won't let Voiceover users make connections, so I 
> can't proceed with Apple's tutorials on this topic. 

While Outlets do make things easier, it's possible to code without them. 
There's an Apple Sample app called "ButtonMadness" that demonstrates 
outlet-based and code-based button creation.

https://developer.apple.com/library/mac/#samplecode/ButtonMadness/Introduction/Intro.html


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to Cocoa/Objective-c: many points of confusion

2013-02-03 Thread Jens Alfke

On Jan 21, 2013, at 10:10 PM, Alex Hall  wrote:

> *delegates: my understanding is that these take the place of subclasses 
> (though why this is useful is beyond me), overriding methods they are 
> designed to handle rather than letting the base class take those methods.

They don’t take the place of subclassing; both are used in Obj-C and Cocoa 
frameworks. They’re different design patterns [if you weren’t exposed to the 
classic Design Patterns book by Gamma et al at school, run out and get a copy.] 
More specifically, delegation is an alternative to overriding methods. It’s 
more flexible in that an object can be a delegate of several other objects, 
even different types of objects.

Delegation also fits in well with MVC designs. It’s pretty common in Cocoa for 
a controller to be the delegate of a view, which lets it handle some of the 
less GUI-centric policy decisions of the view without getting involved in the 
visual details.

> However, I not only don't see why this is so great, but I don't understand 
> the syntax used to declare them or attach them to other classes so the 
> delegates' methods get called when any of those methods are called on the 
> object to which the delegate is attached.

Honestly, there isn’t any particular syntax for delegates. Delegates are not 
part of the language, they’re just a programming convention. (C# is the only 
language I know of that has special built-in syntax for delegation.)

The delegate pattern basically consists of:
* Define an abstract API of messages the class will send its delegate (in Obj-C 
this would usually be an @protocol)
* Declare a ‘delegate’ property of the class, whose type is this protocol
* Synthesize the delegate as an instance variable
* Have the class’s methods call the delegate as appropriate when something 
happens. In some cases they might change the instance’s behavior based on the 
delegate’s return value.

Again, I can’t recommend Gamma et al's “Design Patterns” book highly enough. 
The patterns it describes are the basic building blocks of large-scale software 
design.

> *Every so often I'll see a class between less- and greater-than signs when an 
> example talks about a delegate, but I don't know what this is for. What does 
> it mean to put these symbols around a class (or maybe they are around an 
> object?)?

Those are protocols. The Obj-C language documentation describes them in detail. 
They’re pretty much equivalent to interfaces in Java.

> -(IBAction) someObject:(id)inSender;
> Huh? Is the (IBAction) casting, or a method call, or what (I understand what 
> IBAction is, but not why it is where it is and in parentheses)? I know why 
> the "id" is there, so this action will work with any UI element, but why the 
> colon? What is inSender doing there, hanging out at the end of the line?

U … this is just basic Objective-C syntax for declaring a method. If this 
doesn’t make sense to you, you really need to go re-read the language guide. 
The only oddity here is that “IBAction” is really just a #define for “void”. 
It’s a way to flag a method to Interface Builder as being an action method that 
target actions can be wired up to. The compiler just sees it as a regular 
method returning void.

As for where the ‘sender’ comes from, the convention is that when a control 
messages its target, it passes itself as the parameter to the method. That way 
the object receiving the action can tell what other object invoked the action 
and can check its properties or whatever. This is passed as a parameter by 
convention, because there’s no mechanism built into the language to get the 
object that called a method.

—Jens

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: new to Cocoa/Objective-c: many points of confusion

2013-02-03 Thread Andy Lee
Hi Alex,

Lots of basic topics here that I love to talk about. I'll just focus on 
delegates, at least for now.

On Jan 21, 2013, at 10:10 PM, Alex Hall  wrote:
> *delegates: my understanding is that these take the place of subclasses 
> (though why this is useful is beyond me), overriding methods they are 
> designed to handle rather than letting the base class take those methods. 
> However, I not only don't see why this is so great, but I don't understand 
> the syntax used to declare them or attach them to other classes so the 
> delegates' methods get called when any of those methods are called on the 
> object to which the delegate is attached. Every example I have found seems to 
> indicate they are used only for GUIs, but Apples docs say that they are a 
> much more general-purpose system?
> 
> *Speaking of delegates, I don't follow the syntax used to set them up. Every 
> example seems to love to use views or other UI examples, which would be fine 
> if I could follow that, but I'm not that advanced yet. A more basic, even if 
> not-so-useful-in-reality, example would be very much appreciated.

Comparing delegation to subclassing is exactly the right question. In both 
cases you'd like to change some aspect of how an object behaves. To do this 
with a subclass, as you're used to, you override some method and put the 
desired behavior there. Sometimes that method is one you will call yourself. 
Sometimes it is one that you'll *never* call yourself, but gets called for you 
in the course of the object's lifetime. It depends on the method, in Cocoa as 
in Java.

To use delegation, you put the special behavior in a method of a *different* 
object which you designate as the first object's delegate. To connect the 
delegate in code (as opposed to Interface Builder) the method is almost always 
called setDelegate:. You're just setting an instance variable using a setter 
method, just as you would do in Java.

You typically don't call a delegate method directly. Delegate methods are 
typically called by the object itself, at various points in its lifetime. Often 
they're called just before or after the object does something, hence the 
"willDoSomething" and "didDoSomething" pattern in many delegate method names.

A simple non-visual example that might help is is NSSound, which has just one 
delegate method called sound:didFinishPlaying:. Here's a quick example of 
creating an instance of NSSound and giving it a delegate.

* In Xcode, create a new project of type "Cocoa application".

* In AppDelegate.m, add these lines to the applicationDidFinishLaunching: 
method that has been pre-supplied for you.

NSSound *sound = [NSSound soundNamed:@"Tink"];
[sound setDelegate:self];
[sound play];

* In the same file add the following method to the AppDelegate class:

- (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)finishedPlaying
{
NSLog(@"sound finished");
}

Run the app. (You'll get a compiler warning which you can ignore for now.) You 
should hear a "Tink" sound (it's one of the built-in sounds in Cocoa), and in 
the Xcode Console pane you should see the words "sound finished".

So, why would you do things this way instead of subclassing NSSound and 
overriding the "play" method?

* Separation of concerns. Cocoa is big on separation of concerns. Suppose, 
instead of simply logging a message, you wanted to do some things in the UI 
when the sound finishes playing. Maybe you want to change a text field to say 
"The sound finished playing!" Maybe your UI has a Play/Stop button that shows 
different icons when the sound is playing and when it's not. It doesn't make 
sense for an NSSound subclass to know about user interface. You'd put all that 
behavior in a delegate object that *does* know about user interface, and point 
the NSSound to that delegate. (The delegate would almost certainly be a 
"Controller" in the MVC paradigm, which Cocoa is very big on.)

* Delegates are inherited by subclasses. It's been said that delegation means 
you don't have to subclass, but it happens to provide a benefit when you *do* 
subclass. Suppose there were three subclasses of NSSound, any of which might 
get used (unpredictably) at runtime. With delegation, you're able to specify 
this custom behavior regardless of which subclass gets used. You can add more 
subclasses and they'll inherit this delegation ability as well.

Cocoa delegate methods follow well-defined conventions. For example, notice the 
"did" in "sound:didFinishPlaying:". As I mentioned, "did" and "will" are 
commonly used in delegate method names.

Also note that the first argument to sound:didFinishPlaying: is an NSSound. All 
proper Cocoa delegate methods are structured this way. There may be cases where 
your delegate method cares *which* sound object is doing the delegation. For 
example, you might want to print the name of the sound by modifying the 
delegate method like this:

- (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)finishedP

Re: new to Cocoa/Objective-c: many points of confusion

2013-02-03 Thread Dave Keck
> *delegates: my understanding is that these take the place of subclasses 
> (though why this is useful is beyond me), overriding methods they are 
> designed to handle rather than letting the base class take those methods. 
> However, I not only don't see why this is so great, but I don't understand 
> the syntax used to declare them or attach them to other classes so the 
> delegates' methods get called when any of those methods are called on the 
> object to which the delegate is attached. Every example I have found seems to 
> indicate they are used only for GUIs, but Apples docs say that they are a 
> much more general-purpose system?

> *Speaking of delegates, I don't follow the syntax used to set them up. Every 
> example seems to love to use views or other UI examples, which would be fine 
> if I could follow that, but I'm not that advanced yet. A more basic, even if 
> not-so-useful-in-reality, example would be very much appreciated.

Delegates are indeed a general-purpose pattern -- there are many
instances of non-GUI classes that use the delegate pattern in the
Foundation framework (note that the Foundation framework doesn't
include any GUI functionality, that's all in the AppKit and UIKit
frameworks.) For example, NSFileManager, NSCache, NSPort, and
NSURLConnection all expose delegate interfaces.

The delegate pattern is simply a callout mechanism, allowing one class
to notify another class of some event. The delegate pattern is
inherently limited in that only one delegate can typically be assigned
to a class, but often that limitation isn't an issue. In contrast to
this limitation, notifications (via NSNotificationCenter) are an
alternative callout mechanism that are useful in cases where a class
might expect more than one client to be interested in an event.

A delegate is always an object, and with modern Objective-C, classes
typically declare a delegate protocol with required and optional
methods for the delegate object to implement. For example,
NSFileManager declares the NSFileManagerDelegate protocol. Now say I
have a class called MyFileDelegate; in the interface for
MyFileDelegate, I declare that it conforms to the
NSFileManagerDelegate protocol:

@interface MyFileDelegate 
@end

Now say I assign an instance of MyFileDelegate to be the delegate of
an instance of NSFileManager, via NSFileManager's -setDelegate:
method. Once that's set up, any time I, for example, move a filesystem
object using that NSFileManager instance, that same MyFileDelegate
instance is notified via the -fileManager:shouldMoveItemAtPath:toPath:
method, which MyFileDelegate implements.

> *Outlets: I have a basic idea that these are a way of sending messages from 
> object to object, a bit like listeners. However, I don't really understand 
> the syntax used to make them. Moreover, I always see them used in GUIs, but 
> Xcode's Interface Builder won't let Voiceover users make connections, so I 
> can't proceed with Apple's tutorials on this topic. Somehow, these 
> connections are outlets, or are related to outlets, or some connections are 
> outlets, or something... Anyway, as I can't make the connections to get an 
> idea of how they work, I'm trying to follow others' examples which I don't 
> get as they use code I didn't write and that makes no sense to my newbie 
> brain. So, what exactly is an outlet and how and why would I set one up? 
> Again, a very basic code example would really help here.

I think you've somewhat misunderstood outlets: outlets are references
to objects created in IB. (These objects are typically UI-related,
such as views and buttons.) Outlets can be either an instance variable
or a property.

Now let's say we have a view controller with an outlet (in the form of
an instance variable) to a button that exists inside the view. The
view controller's interface might look like:

@interface MyViewController : UIViewController
{
IBOutlet UIButton *myButton;
}
@end

If I hook up the outlet correctly in IB, every time I instantiate
MyViewController, its 'myButton' instance variable references the
button that exists in its view.

> *Every so often I'll see a class between less- and greater-than signs when an 
> example talks about a delegate, but I don't know what this is for. What does 
> it mean to put these symbols around a class (or maybe they are around an 
> object?)?

There are two different scenarios in which you'll encounter these
less-than/greater-than signs in Objective-C, and both concern the
protocols feature of Objective-C. The first situation is in class
interfaces, where they're used to declare that whatever class you're
creating conforms to the protocol between the less-than/greater-than
signs. Let's continue with NSFileManager to illustrate: NSFileManager
declares the NSFileManagerDelegate protocol. So let's declare a class
called AppController that conforms to NSFileManagerDelegate; the
syntax looks like:

@interface AppController 
@end

The second situation that you'll encoun

Re: new to cocoa

2010-05-16 Thread Charles Srstka
On May 16, 2010, at 8:08 PM, Kyle Sluder wrote:

>> [sourceButtonMap setObject:[NSString stringWithString:@"no"]
>> forKey:[unitButton description]];
> 
> This is a bad idea. Who knows what -description returns? Using a
> textual description of an object intended for debugging in place of
> the actual object is needlessly complex and just plain wrong.

You could probably use an NSMapTable — with the appropriate options, it could 
be set to retain its keys instead of copying them. It might be a good idea to 
see if there’s a better way to do what you’re doing, though — mapping buttons 
to arbitrary objects like that doesn’t strike me as being the best way to do 
things.

Charles___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-16 Thread Andy Lee
In addition to what others have pointed out...

On May 16, 2010, at 8:19 PM, William Squires wrote:
> [sourceButtonMap setObject:[NSString stringWithString:@"no"] 
> forKey:[unitButton description]];

...there's no reason to use stringWithString:.  You can just say:

[sourceButtonMap setObject:@"no" forKey:[unitButton description]];

--Andy

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-16 Thread Jens Alfke

On May 16, 2010, at 5:19 PM, William Squires wrote:

> I believe keys in an NSDictionary/NSMutableDictionary are NSStrings

This is true in a property list; the serializer only knows how to read/write 
strings as dictionary keys. But in memory (or if you’re using the more powerful 
NSArchiver) you can use any copyable object as a dictionary key.

—Jens___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-16 Thread Kyle Sluder
On Sun, May 16, 2010 at 5:19 PM, William Squires  wrote:
> I believe keys in an NSDictionary/NSMutableDictionary are NSStrings; they're
> just descriptive tags you attach (or associate) with an object (the
> "value"). What you need is

Any object can be a key in an NSDictionary, but NSDictionary always
copies its keys. Its toll--free bridged companion, CFDictionary, can
be configured to just retain/release the keys instead.

> [sourceButtonMap setObject:[NSString stringWithString:@"no"]
> forKey:[unitButton description]];

This is a bad idea. Who knows what -description returns? Using a
textual description of an object intended for debugging in place of
the actual object is needlessly complex and just plain wrong.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-16 Thread William Squires
I believe keys in an NSDictionary/NSMutableDictionary are NSStrings;  
they're just descriptive tags you attach (or associate) with an  
object (the "value"). What you need is


[sourceButtonMap setObject:[NSString stringWithString:@"no"] forKey: 
[unitButton description]];


though you'll have to subclass UIButton and implement a description  
method in it for this to do much good.


On May 11, 2010, at 3:36 PM, Alejandro Marcos Aragón wrote:


Hi all,

I'm new to Cocoa, and I couldn't find information about an error  
that I'm getting on the web. I'm trying to create an  
NSMutableDictionary where the keys are of type UIButton*:



// create button for unit
UIButton* unitButton = [[UIButton alloc] init];
			[sourceButtonMap setObject:[NSString stringWithString:@"no"]  
forKey:unitButton];


Of course, the sourceButtonMap is defined in the class and  
initialized in the init function as sourceButtonMap =  
[[NSMutableDictionary alloc] init];


The error I get when I try to add the key-value pair is:

*** Terminating app due to uncaught exception  
'NSInvalidArgumentException', reason: '*** -[UIButton  
copyWithZone:]: unrecognized selector sent to instance 0x3931e90'


Is this happening because I can't store UIButton* as keys?
Can anyone point me why I'm getting this error? Thank you all,

aa___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/wsquires% 
40satx.rr.com


This email sent to wsqui...@satx.rr.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-14 Thread Alejandro Marcos Aragón
Thanks Kiel for answering so fast. I realized that this was the case a couple 
of days ago. It took some time for my message to appear in the mailing list. I 
was trying to associate buttons with objects so that when I press the button I 
can do certain action on the corresponding object. I solved the problem using 
just two regular NSMutableArrays. It's doing the same thing though, creating a 
map of buttons to objects, but using the index to these arrays. It doesn't seem 
to be very efficient though.

aa


On May 13, 2010, at 11:38 PM, Kiel Gillard wrote:

> On 12/05/2010, at 6:36 AM, Alejandro Marcos Aragón wrote:
> 
>> Hi all,
>> 
>> I'm new to Cocoa, and I couldn't find information about an error that I'm 
>> getting on the web. I'm trying to create an NSMutableDictionary where the 
>> keys are of type UIButton*:
>> 
>> 
>>  // create button for unit
>>  UIButton* unitButton = [[UIButton alloc] init];
>>  [sourceButtonMap setObject:[NSString 
>> stringWithString:@"no"] forKey:unitButton];
>> 
>> Of course, the sourceButtonMap is defined in the class and initialized in 
>> the init function as sourceButtonMap = [[NSMutableDictionary alloc] init];
>> 
>> The error I get when I try to add the key-value pair is:
>> 
>> *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
>> reason: '*** -[UIButton copyWithZone:]: unrecognized selector sent to 
>> instance 0x3931e90'
>> 
>> Is this happening because I can't store UIButton* as keys?
> 
> Welcome to iPhone OS development!
> 
> This most certainly is happening because you cannot use UIButton objects as 
> keys in a dictionary because NSDictionary copies the objects used as keys. 
> Furthermore, UIButton does implement the NSCopying methods.
> 
>> Can anyone point me why I'm getting this error? Thank you all,
> 
> 
> 
> See the second paragraph of the section titled "Overview".
> 
> I suggest you revise your design. I don't know exactly what you're trying to 
> do. Perhaps @"no" should be the key for the UIButton?
> 
> Kiel
> 
> 
>> 
>> aa___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/kiel.gillard%40gmail.com
>> 
>> This email sent to kiel.gill...@gmail.com
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-14 Thread Jens Alfke


On May 11, 2010, at 1:36 PM, Alejandro Marcos Aragón wrote:

I'm new to Cocoa, and I couldn't find information about an error  
that I'm getting on the web. I'm trying to create an  
NSMutableDictionary where the keys are of type UIButton*:


Sounds like you're trying to associate data values with buttons. The  
easiest way to do this is to use the control's existing 'tag'  
property, which lets you store an arbitrary integer value. [Actually  
I'm not certain that UIKit controls have tags; their corresponding  
AppKit classes in Mac OS do.]


If you need to store a non-integer value, or have to use a dictionary  
for some other reason, you can use [NSValue valueWithPointer: button]  
to create a value object wrapping a pointer to your button. Those  
values can be used as dictionary keys. To unwrap one, use (UIButton*) 
[value pointerValue]. Just make sure to remove the associated key  
object when a button is deleted, otherwise it's a dangling pointer to  
a deleted object and will cause a crash if you try to use that button  
pointer again.


—Jens___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-13 Thread Kiel Gillard

On 14/05/2010, at 3:15 PM, Ken Thomases wrote:

> On May 13, 2010, at 11:38 PM, Kiel Gillard wrote:
> 
>> This most certainly is happening because you cannot use UIButton objects as 
>> keys in a dictionary because NSDictionary copies the objects used as keys. 
>> Furthermore, UIButton does implement the NSCopying methods.
> 
> I assume you meant "does _not_ implement".

Yes, my apologies. This was an accidental omission. UIButton does NOT implement 
the NSCopying methods.

Thanks, Ken!

> 
> Regards,
> Ken
> 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-13 Thread Ken Thomases
On May 13, 2010, at 11:38 PM, Kiel Gillard wrote:

> This most certainly is happening because you cannot use UIButton objects as 
> keys in a dictionary because NSDictionary copies the objects used as keys. 
> Furthermore, UIButton does implement the NSCopying methods.

I assume you meant "does _not_ implement".

Regards,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-13 Thread Kiel Gillard
On 12/05/2010, at 6:36 AM, Alejandro Marcos Aragón wrote:

> Hi all,
> 
> I'm new to Cocoa, and I couldn't find information about an error that I'm 
> getting on the web. I'm trying to create an NSMutableDictionary where the 
> keys are of type UIButton*:
> 
> 
>   // create button for unit
>   UIButton* unitButton = [[UIButton alloc] init];
>   [sourceButtonMap setObject:[NSString 
> stringWithString:@"no"] forKey:unitButton];
> 
> Of course, the sourceButtonMap is defined in the class and initialized in the 
> init function as sourceButtonMap = [[NSMutableDictionary alloc] init];
> 
> The error I get when I try to add the key-value pair is:
> 
> *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
> reason: '*** -[UIButton copyWithZone:]: unrecognized selector sent to 
> instance 0x3931e90'
> 
> Is this happening because I can't store UIButton* as keys?

Welcome to iPhone OS development!

This most certainly is happening because you cannot use UIButton objects as 
keys in a dictionary because NSDictionary copies the objects used as keys. 
Furthermore, UIButton does implement the NSCopying methods.

> Can anyone point me why I'm getting this error? Thank you all,



See the second paragraph of the section titled "Overview".

I suggest you revise your design. I don't know exactly what you're trying to 
do. Perhaps @"no" should be the key for the UIButton?

Kiel


> 
> aa___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/kiel.gillard%40gmail.com
> 
> This email sent to kiel.gill...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: new to cocoa

2010-05-13 Thread Dave DeLong
Yes, you cannot use UIButton's as keys in a dictionary, because keys in a 
dictionary are copied, and buttons are not copyable.

Here's the better question:  what are you trying to do?  Using buttons as keys 
in a dictionary seems... odd.

Cheers,

Dave

On May 11, 2010, at 2:36 PM, Alejandro Marcos Aragón wrote:

> Hi all,
> 
> I'm new to Cocoa, and I couldn't find information about an error that I'm 
> getting on the web. I'm trying to create an NSMutableDictionary where the 
> keys are of type UIButton*:
> 
> 
>   // create button for unit
>   UIButton* unitButton = [[UIButton alloc] init];
>   [sourceButtonMap setObject:[NSString 
> stringWithString:@"no"] forKey:unitButton];
> 
> Of course, the sourceButtonMap is defined in the class and initialized in the 
> init function as sourceButtonMap = [[NSMutableDictionary alloc] init];
> 
> The error I get when I try to add the key-value pair is:
> 
> *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
> reason: '*** -[UIButton copyWithZone:]: unrecognized selector sent to 
> instance 0x3931e90'
> 
> Is this happening because I can't store UIButton* as keys?
> Can anyone point me why I'm getting this error? Thank you all,
> 
> aa


smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread jmunson
Again, Hillegass' book, "Cocoa Programming for Mac OS X" is excellent.  
 I've a smattering of experience in a number of languages and found  
his book an excellent introduction to the whole bit.


Quoting Benjamin Dobson <[EMAIL PROTECTED]>:


The OP has sent me the original message body off-list. The rest of this
message is what the original message was meant to say.

–––

I've been programming almost exclusively in Java since 1998, and
between 1985 through 1998 I was using C and C++. I just started
learning Objective C, and found the language pretty easy to use.
However, I need some pointers on the best way to become familiar with
some of the Cocoa libraries and classes as well as the Foundation.

In Java, they have  what I think is a great API reference for all the
"normal" classes. For those of you that have never seen it, just so
you'll know what I'm talking about, here's a link:

http://java.sun.com/javase/6/docs/api/

With this you look up the name of a class on the left column, click on
it, and the detail regarding the class shows up on the main section of
the page.

I'm new to this with Cocoa, and I've been looking for something similar
to that above. I have found, for example, the "Foundation Reference
Collection for Objective-C," the "Application Kit Objective-C Reference
Collection," and a host of other similar type pages in the developers
documentation. Each such page displays what can be long lists of
classes, and if you click on one of the Class References, up comes a
page with more detailed information. The information looks pretty
decent, but I end up using the "back" button on the browser to navigate.

Is there a better, easier API layout? Additionally is there one that
would include nearly all frameworks in one list?

Also, I've noticed that some of the newer Objective C texts are using
the "dot" notation. Is this going to be the norm in the future or was
this something added to make Objective C easier to port from Java, C++,
and even C in some cases?

Last but not least, what are the best books available for learning
Objective C and Cocoa? I've had little problems with Objective C
(except adjusting to the notation) so I assume I would want to focus
primarily on Cocoa, and I'm assuming any decent Cocoa book would
probably delve into the Foundation as well, since I don't see how it
couldn't (that's just my opinion).

All opinions welcome, thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jmunson%40his.com

This email sent to [EMAIL PROTECTED]




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread Darren Adkinson

To the OP -

Books:
Hillegass "Cocoa Programming for Mac..." 3rd ed. is great.
"Cocoa Programming" by Anguish, Buck and Yacktman is quite old (2002)  
and only available used but contains some wonderfully lucid  
explanations of facets of Cocoa that are extant today.
Kochan's Obj-C book is useful, even if you don't get the latest Obj-C  
2.0 version.


API browser:
You may want to check out AppKiDo (http://homepage.mac.com/aglee/downloads/appkido.html 
), and of course there's Xcode's documentation browser.


I'm not aware of a Cocoa class libraries poster/wallchart but I'd love  
to get hold of one...


Good Luck!

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread Benjamin Dobson
The OP has sent me the original message body off-list. The rest of  
this message is what the original message was meant to say.


–––

I've been programming almost exclusively in Java since 1998, and  
between 1985 through 1998 I was using C and C++. I just started  
learning Objective C, and found the language pretty easy to use.  
However, I need some pointers on the best way to become familiar with  
some of the Cocoa libraries and classes as well as the Foundation.


In Java, they have  what I think is a great API reference for all the  
"normal" classes. For those of you that have never seen it, just so  
you'll know what I'm talking about, here's a link:


http://java.sun.com/javase/6/docs/api/

With this you look up the name of a class on the left column, click on  
it, and the detail regarding the class shows up on the main section of  
the page.


I'm new to this with Cocoa, and I've been looking for something  
similar to that above. I have found, for example, the "Foundation  
Reference Collection for Objective-C," the "Application Kit Objective- 
C Reference Collection," and a host of other similar type pages in the  
developers documentation. Each such page displays what can be long  
lists of classes, and if you click on one of the Class References, up  
comes a page with more detailed information. The information looks  
pretty decent, but I end up using the "back" button on the browser to  
navigate.


Is there a better, easier API layout? Additionally is there one that  
would include nearly all frameworks in one list?


Also, I've noticed that some of the newer Objective C texts are using  
the "dot" notation. Is this going to be the norm in the future or was  
this something added to make Objective C easier to port from Java, C+ 
+, and even C in some cases?


Last but not least, what are the best books available for learning  
Objective C and Cocoa? I've had little problems with Objective C  
(except adjusting to the notation) so I assume I would want to focus  
primarily on Cocoa, and I'm assuming any decent Cocoa book would  
probably delve into the Foundation as well, since I don't see how it  
couldn't (that's just my opinion).


All opinions welcome, thanks
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread M Pulis

RealBasic is a great tool, cross platform also!

Gary

On Dec 5, 2008, at 3:58 PM, Ian Joyner wrote:


On 06/12/2008, at 8:26 AM, [EMAIL PROTECTED] wrote:

Basic (Beginner's All-Purpose Symbolic Code) was used on Apple IIs  
(although we wrote our own ALGOL-like language at the first Apple- 
based company I worked at). It is generally MIA (like body of  
message!) on Mac, except for third parties like RealBASIC.  
Otherwise, Microsoft still seem to persist, but I would not point  
you in that direction :-)


Ian
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/toothpic%40fastq.com

This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread Ian Joyner

On 06/12/2008, at 8:26 AM, [EMAIL PROTECTED] wrote:

Basic (Beginner's All-Purpose Symbolic Code) was used on Apple IIs  
(although we wrote our own ALGOL-like language at the first Apple- 
based company I worked at). It is generally MIA (like body of  
message!) on Mac, except for third parties like RealBASIC. Otherwise,  
Microsoft still seem to persist, but I would not point you in that  
direction :-)


Ian
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread Benjamin Dobson

On 5 Dec 2008, at 21:26:49, [EMAIL PROTECTED] wrote:





Something wrong with your email?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


RE: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread bvernon

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread Sherm Pendley

OK, here ya go, a basic pointer:

int *basic;

:-)

Seriously though, once you install Xcode and start it up for the first  
time, it presents a window with a list of links at the top. Try  
following the first "Getting Started" link.


sherm--
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread Dave DeLong

Tooting my own horn here...

Our CocoaHeads club maintains an excellent list of Cocoa learning  
resources (books, articles, code, etc):  http://cocoaheads.byu.edu


Dave

On Dec 5, 2008, at 12:14 PM, [EMAIL PROTECTED] wrote:

Start with HILLEGASS' book:  Cocoa Programming for Mac OS X.   
EXCELLENT!

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread jmunson

Start with HILLEGASS' book:  Cocoa Programming for Mac OS X.  EXCELLENT!

Quoting [EMAIL PROTECTED]:



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jmunson%40his.com

This email sent to [EMAIL PROTECTED]





___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread Matt Long

Try this: http://www.matthew-long.com/2007/11/09/xcode-30-tutorial/

Are you new to programming as well or just new to Cocoa/Objective-C?

-Matt


On Dec 4, 2008, at 4:25 PM, [EMAIL PROTECTED] wrote:




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: New to Cocoa and Objective C, and I need some basic pointers

2008-12-05 Thread Shawn Erickson
On Thu, Dec 4, 2008 at 3:25 PM,  <[EMAIL PROTECTED]> wrote:
>

Helpful tip #1... actually ask a question when you email this list. =P

-Shawn
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: new to Cocoa -- threading question

2008-09-07 Thread Mike Abdullah
Also, if you're just playing an MP3 file, look into using QTKit on the  
main thread. Should be very much simpler and Objective C.


On 7 Sep 2008, at 02:35, John Michael Zorko wrote:



Hello, all ...

I'm new to Cocoa, and i'm trying to launch a thread.  Yet, the app  
bombs when I try, and the console says it's because the selector  
isn't implemented:


2008-09-06 18:23:30.919 XXX[2363:20b] SEL: playMP3StreamThread
2008-09-06 18:23:30.927 XXX[2363:20b] *** Terminating app due to  
uncaught exception 'NSInvalidArgumentException', reason: '*** - 
[NSThread initWithTarget:selector:object:]: target does not  
implement selector (*** -[XXXAppDelegate playMP3StreamThread])'


Yet, here it is -- i'm not understanding something obviously (the  
example I saw looked easy enough):


@implementation XXXAppDelegate

.
.
.

- (void)playMP3StreamThread:(Song *)streamToPlay
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	// initialize a mutex and condition so that we can block on buffers  
in use.


pthread_mutex_init(&myData.mutex, NULL);
pthread_cond_init(&myData.cond, NULL);

	OSStatus err = AudioFileStreamOpen(&myData, MyPropertyListenerProc,  
MyPacketsProc,

   
kAudioFileAAC_ADTSType, &myData.audioFileStream);
if (err)
{
NSLog(@"AudioFileOStreamOpen error %d", err);
}

NSString *url = @"http://some_hostl/";;
url = [url stringByAppendingString:streamToPlay.mp3];
	NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL  
URLWithString:[url  
stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]  
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
	NSURLConnection *connection = [[NSURLConnection alloc]  
initWithRequest:request delegate:self];


if (connection)
{
receivedData = [[NSMutableData data] retain];
}
else
{
NSLog(@"can't connect to server");
}

[pool release];
}


- (void)playStream:(Song *)streamToPlay
{
NSLog(@"playing mp3 stream %s", [streamToPlay.mp3 UTF8String]);

// make sure current song play thread is stopped ...






// start a new thread with the new song ...

	[NSThread detachNewThreadSelector:@selector(playMP3StreamThread)  
toTarget:self withObject:streamToPlay];

}

What am I not grokking?  Any pointers would be appreciated ...

Regards,

John




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net

This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: new to Cocoa -- threading question

2008-09-06 Thread John Michael Zorko


Kyle,



  [NSThread  
detachNewThreadSelector:@selector(playMP3StreamThread)

toTarget:self withObject:streamToPlay];


The selector you want is playMP3StreamThread:, not
playMP3StreamThread.  That colon is very important.


Ah, yes -- the colon.  I couldn't live without mine ;-)

*cymbal crash*

Regards,

John, who will be here all week ;-)


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: new to Cocoa -- threading question

2008-09-06 Thread Kyle Sluder
On Sat, Sep 6, 2008 at 9:35 PM, John Michael Zorko <[EMAIL PROTECTED]>
wrote:
>[NSThread detachNewThreadSelector:@selector(playMP3StreamThread)
> toTarget:self withObject:streamToPlay];

The selector you want is playMP3StreamThread:, not
playMP3StreamThread.  That colon is very important.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]