cocoa

WebPageContent problem

I have parsed some data from webpage content and stored it as an NSString. In that string there is a unicode character (\u0097). How can i remove or replace this and avoid all unicode characters? I tried using this line but it hasn't worked: [webpagecontent stringByReplacingOccurrencesOfString:@"\\u0097" withString:@" "]; Can anyone ...

How to Animate scrollpoint?

- (void)mouseDragged:(NSEvent *)theEvent { NSSize dynamicImageSize; dynamicImageSize = [[self image] size]; NSSize contentSize = [(NSScrollView*)[[self superview] superview] contentSize]; if(dynamicImageSize.height > contentSize.height || dynamicImageSize.width > contentSize.width) { float x = startOrigin.x - ...

Limit a double to two decimal places

How do I achieve the following conversion from double to a string: 1.4324 => "1.43" 9.4000 => "9.4" 43.000 => "43" ie I want to round to to decimal places but dont want any trailing zeros, ie i dont want 9.4 => "9.40" (wrong) 43.000 => "43.00" (wrong) So this code which I have now doesn't work as it displays excess twos: [NSString...

Moving every object in my array ?

I have an array an a timer that adds a new object to my array every 5 seconds but am running into a slight issue. I have a code that is called repeatably which moves the objects in my array but for some reason the previous object that spawns will stop moving when a new object is spawned into my array. How do I make it so every single obj...

Xcode question: Quickly jump to a particular selector/class/symbol ?

What is the quickest way to jump to a particular symbol/selector/class in Xcode? (I'm looking for keyboard shortcuts preferably). Right now, I know two ways of doing this: “Open Quickly” > Click on the Symbols dropdown menu at the top of the editor > Select the selector to jump to it. Click on “Project Symbols” in the “Groups and File...

Two Dimension NSMutableArray help?

Ok, I have some C# code that looks like this and I was wondering what other developers would recommend if I am trying to put this into Objective-C. List<List<string>> meta_data I'm planning on using NSMutableArray but how to exactly get that two-dimensional array figured out is my problem, since there is no such thing as a multidimens...

Difference between [[NSMutableDictionary alloc] initWithObjects:...] and [NSMutableDictionary dictionaryWithObjects:...]?

Still learning Objective-C / iPhone SDK here. I think I know why this wasn't working but I just wanted to confirm. In awakeFromNib, if I use [[NSMutableDictionary alloc] initWithObjects:...] it actually allocates (iPhone) system memory with this NSMutableDictionary data, but when I use [NSMutableDictionary dictionaryWithObjects:...] it ...

Testing Nested Error Handling with OCMock

I'd really appreciate some advice around testing for errors using OCMock. Method Under Test It grabs a process using an instance of the AppScriptController class. @implementation ProcessGrabber -(void)grabProcess { NSError *error = nil; NSString *processName = [appScriptController processName:ProcessRef ...

Question about extensiblity of Cocoa Touch Controls

I'm new to programming for the iPhone and i'm wondering: how extensible are the various controls? Let's take the button as an example: can i change the background graphic? can i make it grow larger when i press on it? can i change the font? can i use a custom font? can i use a button graphic in place of text? ...

How do you enable javascript in a WebView

I have a very simple Mac Cocoa app that just has a Web View that loads an HTML file with some CSS and JavaScript. I have hooked up the app delegate to this method: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSString* filePath = [[NSBundle mainBundle] pathForResource: @"index" ofType: @"html"]; NSURL *ur...

getting number of bytes from an instance of NSMutableData

I want to be able to determine if the number of bytes in an instance of NSMutableData is equal to zero. How would I do this? ...

Do Cocoa applications have a main loop?

On Linux under X11 and using GTK+ you have something called "Main Loop". Once you start the main loop you have a timer that runs in the main thread of the application. You can set that timer to a callback function and you have a very nice application-wide timer. This is sample code for that: GMainLoop *loop; if(!loop_running) { ...

Multiple Documents in a Single Window in Cocoa

I want to write an application which may have multiple documents in a single window via a tabbed interface. Should I avoid the NSDocument architecture (the Cocoa Document-based Application template)? As far as I can tell, it supports only one or more window per document but not vice versa. I have been wrestling with this question for ...

Cocoa: Getting the current mouse position on the screen

I need to get the mouse position on the screen on a Mac using Xcode. I have some code that supposedly does that but i always returns x and y as 0: void queryPointer() { NSPoint mouseLoc; mouseLoc = [NSEvent mouseLocation]; //get current mouse position NSLog(@"Mouse location:"); NSLog(@"x = %d", mouseLoc.x); NSLog...

When porting Java code to ObjC, how best to represent checked exceptions?

I am working on porting a Java codebase to Cocoa/Objective-C for use on desktop Mac OS X. The Java code has lots and lots of methods with checked exceptions like: double asNumber() throws FooException { ... } What's the best way to represent these in Objective-C? Exceptions or error out-parameters? - (CGFloat)asNumber { ... ...

Is there a HTML wrapper in Cocoa other then UIWebView?

I have a bunch of texts and images (taken from the content tag of a RSS feed item) that I want to display in my app. I've managed to extract them from the entire content tag with some regular expressions. But the thing is, in order for the texts to appear before all the images are loaded, I need to preload all the images, and even more, ...

Is a launchd daemon the best route to go for reading/writing to privileged files in Cocoa?

I have an application which needs to be able to write to Any User/Current host preference files (which requires admin privileges per Preferences Utilities Reference) and also to enable/disable a launchd agent via its plist (writable only by root). I'm using SFAuthorizationView to require users to authenticate as an admin before alterin...

release/autorelease confusion in cocoa for iphone

I'm slowly teaching myself cocoa for the iPhone(through the Stanford Class on iTunes U) and I've just gone through the part on memory management, and I wanted to hopefully get some confirmation that the assumptions I'm making on how memory is handled and how [release] and [autorelease] work. Since memory management is a really basic and...

Should frameworks be put in /Library/Frameworks or in the application bundle when putting multiple applications in one bundle

I have an application composed of a GUI and 3 launchd daemon launched command-line executables. I'm planning to put the executables for the launchd daemons inside the .app bundle for the GUI. These apps utilize 2 (both fairly small) frameworks which I have created. Is it a better idea to put these frameworks in /Library/Frameworks (an...

Error: incompatible types in assignment

I am writing some objective-C code and i can't figure out why this does not work: buttonRect = CGRectMake(0,0,100.0,100.0);//error:incompatible types in assignment CGRect newFrame = CGRectInset(buttonRect, -0.2, -0.2);//error:incompatible type for argument 1 of CGRectInset button.frame = newFrame; buttonRect is a CGRect defined as an ...