cocoa

Merging NSArrays in Objective-C

I have an NSDictionary where each key points to an array. I later want to merge all of the values into one array. Is there a way to use the API to do something more efficient than say: NSArray *anArray = [someDictionary allValues]; NSArray *newArray = [NSMutableArray array]; start outter loop on anArray start inner loop on objects in...

Cocoa/Objective-C: how much optimization should I do myself?

I recently found myself writing a piece of code that executed a Core Data fetch, then allocated two mutable arrays with the initial capacity being equal to the number of results returned from the fetch: // Have some existing context, request, and error objects NSArray *results = [context executeFetchRequest:request error: NSMutableArra...

NSData subdataWithRange question

Hello, i feel like having memory leak in the next code while([outData length] + ptr[currentPacket].mDataByteSize < inBytesToGet && currentPacket < packetsCount) { NSLog(@" ++> %d", [aData retainCount]) ; NSInteger sO = ptr[currentPacket].mStartOffset ; NSInteger dS = ptr[currentPacket].mDataByteSize ; NSLog(@" get: cP: %d...

Proper way to use Objective C

This isn't a style question. Its more about the proper use of the language itself. I'm am fairly new to programming and I'm totally new to Objective-C and Cocoa but after reading about the language and looking through some sample code some usage patterns continue to pop up that do not make sense to me. Or rather they seem non optimal in ...

Constant kCGColors deprecated on iPhone?

I'm having some trouble getting CGColorGetConstantColor() to work on the iPhone. Apple's documentation claims you can pass any of the "Constant Colors" without linking to what the Constant Colors actually are, so I assumed you can simply use those documented for OS X: CGColorRef blackColor = CGColorGetConstantColor(kCGColorBlack); Thi...

How to create an iPod-esque UISlider

Does anyone have a quick way to make a UISlider that looks like the ones in the iPod app (think scrubber/volume control). Basically I need something that looks exactly like an MPVolumeView, but doesn't control sound. Failing that, does anyone have the assets to make one (the knob/track). ...

NSString to FSRef conversion doesn't work

Hi, For my app I need to use the Carbon file manager API to get the size of a folder (NSEnumerator is slow, and using NSTask with a shell command is even worse). I've imported the Carbon framework, and I'm using this method to get the size of a folder: http://www.cocoabuilder.com/archive/message/cocoa/2005/5/20/136503 It uses an FSRef...

Acessing Mac applications from Ruby or PHP or Cocoa

I would like to access a couple of different Mac OS X applications from preferably Ruby, but I would settle for PHP. The applications are Elgato's turbo.264 and Apple's iTunes. Both have Applescript Libraries defined that would allow me to do what I want to do from Applescript, but I don't want to do this in Applescript. If I can't do th...

Objective-C modify parameter to method at runtime

I'd like to change the value of a parameter at runtime and curious how this works in Obj-C. I have a loop where value of 'n' is 0 increasing by 1 with each loop. How does one increment the passed parameter by 1 as n moves. UIViewSubclass *uiViewSubclass = [[UIViewSubclass alloc] initWithValue:([value integerValue]) ...

Can I edit the pixels of the UIImage's property CGImage

UIImage has a read-only property CGImage. I have to read its pixels to a memory block and edit them and then make a new UIImage to replace the old one. I want to know if there is a way bypass the read-only property and edit those pixels directly. Thanks. Thanks all. I have found a way to do it. Write a class with those method: -(vo...

How do you use Objective-C starting from the "Java JNI Application" template in XCode?

I want to use the NSStatusBar object from my Java application using JNI. I know there's some existing libraries out there but I've tried them and they don't have the correct drop down menu. I'm starting from the "Java JNI Application" template in XCode and I simply put NSString *str=@""; to see if it could compile but this produces ...

How to obtain accurate decibel leve with Cocoa?

We are creating an application which records the surrounding sound and take necessary action if the sound crosses specified Decibel. In order to achieve the application objective we are using following method from AudioQueueObject.h - (void) getAudioLevels: (Float32 *) levels peakLevels: (Float32 *) peakLevels { UInt32 propertySize...

How to make an NSString path (file name) safe

Hi, I'm using very tricky fighting methods :) to make a string like 'Fi?le*/ Name' safe for using as a file name like 'File_Name'. I'm sure there is a cocoa way to convert it. And I'm sure the best place to ask is here :) Thank you! ...

Obtain list of class methods for an arbitrary class

How can I get the list of class methods for a particular Class? I've tried using the class_copyMethodList function declared in <objc/runtime.h>, but that's only giving me instance methods. I've also found a function that gives me a Method for a class method, but only if I have the selector to the method first (class_getClassMethod). A...

Model for localizable attribute values in Core Data Entity?

If I want to create a entity in Core Data that has attributes with values that should be localizable I'm wondering how the most efficient way would look like? As a example let's assume the following structure: Book name (localizable) description (localizable) author An localized book entry would look like this: name: ...

Ordinal Month-day Suffix Option for NSDateFormatter setDateFormat

What setDateFormat option for NSDateFormatter do I use to get a month-day's ordinal suffix? e.g. the snippet below currently produces: 3:11 PM Saturday August 15 What must I change to get: 3:11 PM Saturday August 15**th** NSDate *date = [NSDate date]; NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [date...

Generating HTML programmatically

In C#, I use XML/XSLT transformation to isolate markup from data. What's the equivalent in Objective C? ...

Is there a cocoa library for advanced date + time handling?

I need to do some date + time stuff that is not covered well by NSDate on the iPhone. I wonder if there is a library that has more sophisticated functionality regarding dates and time on a international level. What I want to do is advanced date + time mathemathics. I need to: convert between different calendar types (Gregorian <> Jewi...

Do I have to autorelease this object?

I am creating an NSDictionary with -initWithObjectsAndKeys:. For every object I provide to that dictionary I call a selfmade method -createFooBarObject, which will create and return the object. Now the problem: The create method by definition should not release the object because it must return it, and the caller is responsible for rel...

Odd problem using addObserver:forKeypath:options:context: in init method

According to Apple and numerous examples I've seen, there is no problem using KVO/KVC to observer yourself. Also according to those same sources, it's not a problem setting this up by using addObserver:forKeypath:options:context: in an object's init method, a la: - (id)init { self = [super init]; if (self) { [self addObserv...