Re: ScriptingBridge Not working same as Applescript

2011-06-12 Thread Eric Wing
On 6/12/11, Abhinav Tyagi  wrote:
> Hi,
>
> I am trying to get the details of current track being played in iTunes
> from cocoa application. I am using ScriptingBridge
> by generating iTunes from the command line using
>
> The Applescript which i have successfuly tested in ScriptEditor is
>
> tell application "iTunes"
>   set strSongTitle to (get name of current track)
>   set strSongAuthor to (get artist of current track)
>   set songClass to (class of current track)
>   set currentPlayPosition to (player position)
>   if songClass is URL track then
>   set playURL to (get address of current track)
>   set nCurrentTrackLengthInSeconds to (0)
>   else
>   set playURL to (get location of current track)
>   set nCurrentTrackLengthInSeconds to (get duration of current 
> track)
>   end if
>   set state to (get player state)
> end tell
>
> I am not sure why the currentStreamURL property of
> iTunesApplication:SBApplication is returning nil?
> Also pushed the sample to READ+WRITE GIT which can be found at:
> https://abhinavty...@github.com/abhinavtyagi/iTunesCocoa.git
>
> I dont know if i am doing somenthing wrong with this.
> --
> Abhinav


I've noticed that some commands don't work even though they appear in
the dictionary. And some commands (e.g. playOnce) may have once
worked, but no longer. I don't really know why, and I don't know the
true relationship between AppleScript and ScriptingBridge.

I recommend filing a bug if you haven't already done so.

-Eric
-- 
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
___

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: Parent-child Design Pattern

2011-06-12 Thread Martin Hewitson
Thanks to all for the answers. Since I wasn't planning on a tree type view, I 
missed the inherent tree nature of the model. So having a mediating layer of 
objects (Nodes) seems to be the way to go.

Martin



On 12, Jun, 2011, at 10:08 PM, Quincey Morris wrote:

> On Jun 12, 2011, at 12:12, Martin Hewitson wrote:
> 
>> Suppose I have a model object Parent which contains an array of Child 
>> objects.
>> 
>> Then I have a ParentView object and a corresponding ParentViewController. 
>> The controller has a reference to the Parent and to the ParentView and so 
>> can act as a data source for the view.  So far, so good.
>> 
>> What I'm unsure about is, how to deal with the children objects. I will, in 
>> principle, have a ChildView. This raises some questions:
>> 
>> 1) Should I have a ChildViewController class?
>> 2) Where do I keep the array of ChildView classes? In the ParentView? And 
>> how do I ensure that each ChildView is associated with the appropriate Child 
>> object?
>> 3) If I do have a ChildViewController class, where should I keep the array 
>> of these? In the ParentViewController? 
> 
> Here's how I've done this:
> 
> -- You need a class to represent your data model objects in the user 
> interface. In the past I've rolled my own, but now I would suggest starting 
> with NSTreeNode and subclassing it.
> 
> -- In your NSTreeNode subclass, add a "representation" property of type 'id' 
> to go along with the "representedObject" property it already has. Note that 
> you only need one NSTreeNode subclass, since you find out what an instance is 
> used for by looking at the class of the instance's "representedObject" and/or 
> "representation" objects. (In particularly complex designs it might be 
> worthwhile having multiple subclasses, but I wouldn't do that unless it 
> proved necessary.)
> 
> -- The tree node's "representedObject" is set, of course, to a Parent or 
> Child or other object in your data model.
> 
> -- The tree node's "representation" is set to a NSViewController (possibly a 
> subclass if you need it) that represents the ParentView or ChildView.
> 
> -- By setting the tree node's "parent" and "children" relationships, you 
> construct a hierarchy of tree nodes that encapsulate both the data model (via 
> "representedObject") and the views (via "representation"). The hierarchy 
> often matches the hierarchy in the data model, but it doesn't have to.
> 
> -- It's often convenient to have some tree nodes (e.g. a root node) that 
> don't correspond to a data model object, and you can set the 
> "representedObject" to nil or something else. Similarly, it's often 
> convenient to have some that don't correspond to a view. In that case, I 
> typically set the representation to a string. Sometimes the string *is* the 
> representation of the object that you want to draw somewhere in the UI (e.g. 
> in an outline view); sometimes you can use it just as a way of recognizing 
> the node.
> 
> In your controller, you work with the tree nodes primarily, because you can 
> get from them to the data model and the views.
> 
> If you need a ParentViewController and/or a ChildViewController that's a 
> subclass of NSViewController -- and you probably will -- then by all means 
> use them. They're mediating controllers, though.
> 
> For your coordinating controller, you almost always should use a window 
> controller subclass, and *not* (for example) the ParentViewController. The 
> window controller is responsible for building and maintaining the tree nodes, 
> and for arranging for the correct set of parent and child views to be visible 
> at any given time. Almost all of such behavior needs to consider the window 
> context as a whole, so it tends to confuse matters to tie the behavior to a 
> specific view.
> 
> I believe that the above arrangement makes use of the current "best 
> practices" for window controllers, view controllers and views, and I've found 
> the design pattern very easy to work with.
> 
> HTH
> 
> 


Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer 
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: martin.hewit...@aei.mpg.de
WWW: http://www.aei.mpg.de/~hewitson






___

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: [iOS] Any way to connect to serial port in simulator?

2011-06-12 Thread Rick Mann

On Jun 12, 2011, at 19:19 , Rick Mann wrote:

> Is there any way to connect to a serial port under the emulator? Calls like 
> open() and fcntl() are hidden in the headers, as are constants like O_RDWR, 
> O_NOCTTY, et al.

Oh, nevermind, it seems that the necessary header is included a little bit 
differently under iOS. Had to explicitly include .

-- 
Rick


___

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: ObjC stdin equivalent? and other questions

2011-06-12 Thread Jens Alfke

On Jun 10, 2011, at 7:56 PM, William Squires wrote:

>  Can a console app control the text 'cursor' in Terminal.app's window solely 
> through stdio? (i.e. are there control codes that clear the screen, locate 
> the cursor at some x,y location, set the text color/brightness (I know the 
> man page reader can, at the very least, change the text brightness), position 
> the cursor at the beginning/end of a line, etc…)

The Terminal app is just emulating an ANSI standard terminal. Search for “ANSI 
escape sequences” if you want the gory details. You basically write magic 
character sequences starting with ESC to stdout.

—Jens

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


ScriptingBridge Not working same as Applescript

2011-06-12 Thread Abhinav Tyagi
Hi,

I am trying to get the details of current track being played in iTunes
from cocoa application. I am using ScriptingBridge
by generating iTunes from the command line using

The Applescript which i have successfuly tested in ScriptEditor is

tell application "iTunes"
set strSongTitle to (get name of current track)
set strSongAuthor to (get artist of current track)
set songClass to (class of current track)
set currentPlayPosition to (player position)
if songClass is URL track then
set playURL to (get address of current track)
set nCurrentTrackLengthInSeconds to (0)
else
set playURL to (get location of current track)
set nCurrentTrackLengthInSeconds to (get duration of current 
track)
end if
set state to (get player state)
end tell

I am not sure why the currentStreamURL property of
iTunesApplication:SBApplication is returning nil?
Also pushed the sample to READ+WRITE GIT which can be found at:
https://abhinavty...@github.com/abhinavtyagi/iTunesCocoa.git

I dont know if i am doing somenthing wrong with this.
-- 
Abhinav

--One who asks is seen as a fool, the one who doesnt asks remain a fool forever
___

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: Is it possible to create a Finder-like icon in Dock?

2011-06-12 Thread Richard Somers
On Jun 12, 2011, at 6:22 PM, Nick wrote:

> Finder behaves differently...
> 
> Would it be possible to create a similar icon?

Probably not. At least I would hope I would be impossible or at least very 
difficult for a developer to do this. From a users perspective I don't think I 
would appreciate a third party application whose Dock icon would behave like 
Finder. As a user and as a developer I appreciate the consistency that Mac OS X 
provides.

--Richard

___

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


[iOS] Any way to connect to serial port in simulator?

2011-06-12 Thread Rick Mann
Is there any way to connect to a serial port under the emulator? Calls like 
open() and fcntl() are hidden in the headers, as are constants like O_RDWR, 
O_NOCTTY, et al.

I'm a licensed MFi developer, so I can actually connect via the EA framework on 
a device, but it's a pain to not be able to use the simulator, and the hardware 
isn't quite ready yet.

-- 
Rick

___

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


Is it possible to create a Finder-like icon in Dock?

2011-06-12 Thread Nick
Hi!

Most (if not all) applications in OS X, when started, have an icon of a
running application in Dock. When a user quits this application, it either
disappears from Dock, or remains there if "Keep in Dock" options has been
selected.

Finder behaves differently. When it is running, it does not have an item
"Quit" in its Menu. When it does not run, it does not have an item "Remove
from Dock". One can not move it into other than the first position in Dock
(or drag it out of Dock to delete its icon). Instead of "Force Quit" in its
Dock menu it has "Relaunch". The only thing it has similar to other apps -
is a "Force Quit" option when Finder is in state "Application Not
Responding".

Would it be possible to create a similar icon? Is it hardcoded in Dock, or
by manipulating with Dock's plist or some other way I could make an another
application behave like this?
___

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: Memory Management for XML Parsing

2011-06-12 Thread Jens Alfke

On Jun 12, 2011, at 2:44 AM, Bing Li wrote:

> The NSArray, nodes, is created by xmlDoc. Since the method is not the owner,
> nodes should be released here.

No, you don’t need to release ‘nodes' since you didn’t allocate or copy it.

> When a large number of XML is received, the
> receiver's memory is increased slowly.

Are you calling that method as part of a loop? If so, try allocating an 
autorelease pool at the top of the loop and draining it at the end. Basically, 
autoreleased objects don’t go away till the topmost autorelease pool drains, 
and if you’re doing a whole lot of stuff before returning to the event loop, 
you need to set up your own autorelease pool or everything will pile up till 
you finally finish.

In general it looks something like:

while (…) {
NSAutoreleasePool* pool = [NSAutoreleasePool new];
… do stuff …
[pool drain];
}

‘pool’ will collect all the references that get autoreleased during ‘do stuff’, 
and then release them when it’s drained.

—Jens

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: Parent-child Design Pattern

2011-06-12 Thread Greg Guerin

Martin Hewitson wrote:

What I'm unsure about is, how to deal with the children objects. I  
will, in principle, have a ChildView. This raises some questions:


1) Should I have a ChildViewController class?



I don't think there's a single answer.  Parent/child relationships  
can be presented in many ways.  For example, see here:


http://designingwebinterfaces.com/designing-web-interfaces-12-screen- 
patterns


Many of those designs have some form of hierarchical data models, yet  
the views and view controllers may not have the same structure.


You should figure out what the view relationships are, then design  
view controllers accordingly. The role of the class is a VIEW  
controller, not a MODEL controller; it doesn't have to mirror the  
MODEL's structure.


  -- GG


___

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: Parent-child Design Pattern

2011-06-12 Thread Quincey Morris
On Jun 12, 2011, at 12:12, Martin Hewitson wrote:

> Suppose I have a model object Parent which contains an array of Child objects.
> 
> Then I have a ParentView object and a corresponding ParentViewController. The 
> controller has a reference to the Parent and to the ParentView and so can act 
> as a data source for the view.  So far, so good.
> 
> What I'm unsure about is, how to deal with the children objects. I will, in 
> principle, have a ChildView. This raises some questions:
> 
> 1) Should I have a ChildViewController class?
> 2) Where do I keep the array of ChildView classes? In the ParentView? And how 
> do I ensure that each ChildView is associated with the appropriate Child 
> object?
> 3) If I do have a ChildViewController class, where should I keep the array of 
> these? In the ParentViewController? 

Here's how I've done this:

-- You need a class to represent your data model objects in the user interface. 
In the past I've rolled my own, but now I would suggest starting with 
NSTreeNode and subclassing it.

-- In your NSTreeNode subclass, add a "representation" property of type 'id' to 
go along with the "representedObject" property it already has. Note that you 
only need one NSTreeNode subclass, since you find out what an instance is used 
for by looking at the class of the instance's "representedObject" and/or 
"representation" objects. (In particularly complex designs it might be 
worthwhile having multiple subclasses, but I wouldn't do that unless it proved 
necessary.)

-- The tree node's "representedObject" is set, of course, to a Parent or Child 
or other object in your data model.

-- The tree node's "representation" is set to a NSViewController (possibly a 
subclass if you need it) that represents the ParentView or ChildView.

-- By setting the tree node's "parent" and "children" relationships, you 
construct a hierarchy of tree nodes that encapsulate both the data model (via 
"representedObject") and the views (via "representation"). The hierarchy often 
matches the hierarchy in the data model, but it doesn't have to.

-- It's often convenient to have some tree nodes (e.g. a root node) that don't 
correspond to a data model object, and you can set the "representedObject" to 
nil or something else. Similarly, it's often convenient to have some that don't 
correspond to a view. In that case, I typically set the representation to a 
string. Sometimes the string *is* the representation of the object that you 
want to draw somewhere in the UI (e.g. in an outline view); sometimes you can 
use it just as a way of recognizing the node.

In your controller, you work with the tree nodes primarily, because you can get 
from them to the data model and the views.

If you need a ParentViewController and/or a ChildViewController that's a 
subclass of NSViewController -- and you probably will -- then by all means use 
them. They're mediating controllers, though.

For your coordinating controller, you almost always should use a window 
controller subclass, and *not* (for example) the ParentViewController. The 
window controller is responsible for building and maintaining the tree nodes, 
and for arranging for the correct set of parent and child views to be visible 
at any given time. Almost all of such behavior needs to consider the window 
context as a whole, so it tends to confuse matters to tie the behavior to a 
specific view.

I believe that the above arrangement makes use of the current "best practices" 
for window controllers, view controllers and views, and I've found the design 
pattern very easy to work with.

HTH


___

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: Parent-child Design Pattern

2011-06-12 Thread Joanna Carter
Le 12 juin 2011 à 20:12, Martin Hewitson a écrit :

> This is a question about choosing the correct design pattern for a particular 
> application. This application is generic enough that I can describe it by a 
> simple parent-child model.
> 
> Suppose I have a model object Parent which contains an array of Child objects.
> 
> Then I have a ParentView object and a corresponding ParentViewController. The 
> controller has a reference to the Parent and to the ParentView and so can act 
> as a data source for the view.  So far, so good.
> 
> What I'm unsure about is, how to deal with the children objects. I will, in 
> principle, have a ChildView. This raises some questions:
> 
> 1) Should I have a ChildViewController class?
> 2) Where do I keep the array of ChildView classes? In the ParentView? And how 
> do I ensure that each ChildView is associated with the appropriate Child 
> object? 
> 3) If I do have a ChildViewController class, where should I keep the array of 
> these? In the ParentViewController? 
> 
> I can see a complicated spagehti system arising here. Suppose I don't only 
> have a Parent-Child system, but a deeper tree (A contains an array of B, each 
> B contains an array of C, etc), how should one extend the scheme?
> 
> I'm guessing this is a generic enough situation that there exists a 
> best-practice for handling it. For some reason, I can't arrive at it myself, 
> so far. Any hints, keywords or clues would be well received.

This sounds like a typical tree structure. The basic structure is:

Node
  Node *parent
  NSArray *childNodes // contains instances of Node

NodeView
  NodeView *parentView
  NSArray *childViews // contains instances of NodeView

The Model takes this structure and so should the View.

I would say that you should design a NodeController and then derive from that 
class to add a ParentNodeController.

Joanna

--
Joanna Carter
Carter Consulting

___

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


Parent-child Design Pattern

2011-06-12 Thread Martin Hewitson
Dear List,

This is a question about choosing the correct design pattern for a particular 
application. This application is generic enough that I can describe it by a 
simple parent-child model.

Suppose I have a model object Parent which contains an array of Child objects.

Then I have a ParentView object and a corresponding ParentViewController. The 
controller has a reference to the Parent and to the ParentView and so can act 
as a data source for the view.  So far, so good.

What I'm unsure about is, how to deal with the children objects. I will, in 
principle, have a ChildView. This raises some questions:

1) Should I have a ChildViewController class?
2) Where do I keep the array of ChildView classes? In the ParentView? And how 
do I ensure that each ChildView is associated with the appropriate Child 
object? 
3) If I do have a ChildViewController class, where should I keep the array of 
these? In the ParentViewController? 

I can see a complicated spagehti system arising here. Suppose I don't only have 
a Parent-Child system, but a deeper tree (A contains an array of B, each B 
contains an array of C, etc), how should one extend the scheme?

I'm guessing this is a generic enough situation that there exists a 
best-practice for handling it. For some reason, I can't arrive at it myself, so 
far. Any hints, keywords or clues would be well received.

Best wishes,

Martin


Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer 
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: martin.hewit...@aei.mpg.de
WWW: http://www.aei.mpg.de/~hewitson






___

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: Memory Management for an Array

2011-06-12 Thread Scott Ribe
On Jun 12, 2011, at 12:29 PM, Bing Li wrote:

> Do you think the below method is a correct solution to manage memory? I am
> not sure if the array, nodes, could leak?

Really, follow the memory management rules as written and as pointed out to you 
before. That is how you know you're writing correct code.

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

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: Memory Management for an Array

2011-06-12 Thread Tito Ciuro
Hi Bing,

Looks good. One comment though: I would return nil instead of an empty string 
to differentiate an actual value (the empty string) vs. "nothing was read."

-- Tito

On Jun 12, 2011, at 11:29 AM, Bing Li wrote:

> Dear all,
> 
> Do you think the below method is a correct solution to manage memory? I am
> not sure if the array, nodes, could leak?
> 
> Thanks so much!
> 
> Best regards,
> Bing
> 
> + (NSString *)read:(NSString *)xml Path:(NSString *)xPath
> {
>NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithXMLString:xml
> options:NSXMLDocumentTidyXML error:NULL];
>NSArray *nodes = [xmlDoc nodesForXPath:xPath error:NULL];
>[xmlDoc release];
>if ([nodes count] > 0)
>{
>return [[nodes objectAtIndex:0] stringValue];
>}
>else
>{
>return @"";
>}
> }
> ___
> 
> 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/tciuro%40mac.com
> 
> This email sent to tci...@mac.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


Memory Management for an Array

2011-06-12 Thread Bing Li
Dear all,

Do you think the below method is a correct solution to manage memory? I am
not sure if the array, nodes, could leak?

Thanks so much!

Best regards,
Bing

+ (NSString *)read:(NSString *)xml Path:(NSString *)xPath
{
NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithXMLString:xml
options:NSXMLDocumentTidyXML error:NULL];
NSArray *nodes = [xmlDoc nodesForXPath:xPath error:NULL];
[xmlDoc release];
if ([nodes count] > 0)
{
return [[nodes objectAtIndex:0] stringValue];
}
else
{
return @"";
}
}
___

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: Getting CGColor components

2011-06-12 Thread Andreas Mayer

Am 12.06.2011 um 01:12 schrieb Development:

> According to all the examples I have found the following code should give me 
> the RGB components of any UIColor.CGColor I pass to it

CGColorGetComponents() will only give you RGB components if the color actually 
*is* a RGB color.

You should check that with CGColorGetColorSpace() beforehand.


Andreas___

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


Memory Management for XML Parsing

2011-06-12 Thread Bing Li
Dear all,

I got another memory management problem. When an XML is received, it must be
parsed using the below method. When a large number of XML is received, the
receiver's memory is increased slowly. I tried to figure out where the
memory leaks. I guess the method might cause this problem.

The NSArray, nodes, is created by xmlDoc. Since the method is not the owner,
nodes should be released here. One value of the array must be returned. Does
the value leak? The method below is correct?

Thanks so much for your help!

Best regards,
Bing

+ (NSString *)read:(NSString *)xml Path:(NSString *)xPath
{
NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithXMLString:xml
options:NSXMLDocumentTidyXML error:NULL];
NSArray *nodes = [xmlDoc nodesForXPath:xPath error:NULL];
[xmlDoc release];
if ([nodes count] > 0)
{
return [[nodes objectAtIndex:0] stringValue];
}
else
{
return Constants.WWW.EMPTY_STRING;
}
}
___

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