objective-c

Why is float getting rounded off in this Objective C / Cocoa code

I am doing a simple : float x = 151.185436; printf("x=%f",x); and the result is x=151.185440 Whats wrong here? I want to retain and print my original value of 151.185436 Thanks Amarsh ...

Is there a way to automatically uppercase comments in Xcode?

Is there a way to automatically uppercase comments in Xcode? Either when typing individual comments or globally after the fact? ...

Iphone App crashing on launch

Hey, My simple iphone app is crashing on launch, it says "the application downloadText quit unexcpectedly i none of these windows that pop up when a mac app crashes and has a send to Apple button. My .h is below and i would greatly appreciate it if anyone could give me a hand as to what's wrong? thanks, Declan ` #import "downloadTextV...

Problem with Three20 TTPhotoViewController

Hi there, I am not sure if this is the right place to ask or report this... but i hope someone here can help me out with the following problem I'm currently creating an app which offers several functionalities. anyways it also includes the TTPhotoViewController which Three20 offers. Well this controller is absolutely awesome but i'm ha...

WebKit & Objective-C: how to parse a HTML string into a DOMDocument?

How do you get a DOMDocument from a given HTML string using WebKit? In other words, what's the implementation for DOMDocumentFromHTML: for something like the following: NSString * htmlString = @"<html><body><p>Test</body></html>"; DOMDocument * document = [self DOMDocumentFromHTML: htmlString]; DOMNode * bodyNode = [[document getElemen...

Is it generally faster to call an instance method rather than a class method?

Today I encountered something strange: I tried to put a utility method into an Utility class as a class method, so that I can simply call that method to generate me an convenient UIView with no hassle (not the imageNamed method but the other, much more complex one). It was horrible. The performance was so incredible bad. Then I made an i...

Whats the scope of a c function defined within objective-c class?

I was reading up about bypassing objective-c's messaging to gain performance (irrelevant to this specific question) when i found an interesting bit of code: #import <Cocoa/Cocoa.h> @interface Fib : NSObject { } - (long long) cFib: (NSUInteger) number; @end @implementation Fib // c implementation of fib long long cFibIMP(NSUInteger ...

How can I make the Tab key move focus out of a NSTextView?

I'm using an NSTextView to allow multi-line input. However, due to the nature of my app, users will be more comfortable moving to the next input element when they press TAB. How can I make TAB exit the NSTextView, while keeping the newline behaviour of the Enter key? ...

UIActionSheet positioning problem

I need to display a pop with a UISwitch and a Done button when user taps on a button and save the state of the switch when the done button in the pop up is tapped. So I use UIActionSheet to do this - sheet = [[UIActionSheet alloc] initWithTitle:@"Switch Setting" delegate:self ...

How to allow one thread to mutate an array property while another thread iterates on a copy of the array

I would like to implement an observer pattern in Objective-C where the observer implements an interface similar to SKPaymentTransactionObserver and the observable class just extends my base observable. My observable class looks something like what is below. Notice I'm making copies of the observers before enumeration to avoid throwing ...

Simple if statement for checking whether a co-ordinate is inside a square?

I have an UIImageView and taking the raw touch input. I need to check if a touch is within a certain set of squares. At the moment... I have this if statement.... if(46 < touchedAt.x && touchedAt.x < 124 && 18 < touchedAt.y && touchedAt.y < 75) but I have tried to simplify it to this one... if(46 < touchedAt.x < 124 && 18 < touchedA...

Why does my program crash when given negative values?

Alright, I am very confused, so I hope you friends can help me out. I'm working on a project using Cocos2D, the most recent version (.99 RC 1). I make some player objects and some buttons to change the object's life. But the weird thing is, the code crashes when I try to change their life by -5. Or any negative value for that matter,...

Anyway to get string from variable name?

Say I have my class @interface Person : NSObject { NSString *name; } I need to get the name of NSString's within my class Person *person = [[Person alloc] init]; NSLog(@"Name of variable %s\n", _NameofVariable_(person->name)); Thanks for the answers, here's the solution I came up from the replies //returns nil if property is no...

Calculating negative fractions in Objective C

I've been coding my way through Steve Kochan's Programming in Objective-C 2.0 book. I'm up to an exercise in chapter 7, ex 4, in case anyone has the book. The question posed by the exercise it will the Fraction class written work with negative fractions such as -1/2 + -2/3? Here's the implementation code in question - @implementation ...

How do i get an MKAnnotationView's coords?

I have a method like this: - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control Using this, can i get the coordinates? ...

I-Phone: Trying to check an Array for an item based on a string produced

Hello! I'm writing a program that will concatenate a string based on letters, and then check an array to see if that string exists. If it does, then it will print a line in IB saying so. I've got all the ins-and-outs worked out, save for the fact that the simulator keeps crashing on me! Here's the code: -(IBAction)checkWord:(id)sende...

What's better practice: objc_msgSendv or NSInvocation?

So I'm working on something in obj-c (I'd rather not say what) where I need to be able to call arbitrary methods on arbitrary objects with arbitrary variables. The first two are easy enough to do, but I am unsure how to do the variable arguments. To be clear, this is not about a function/method receiving variable arguments, but about s...

Storing and retrieving CGPoints inside NSMutableArray

I've looked through countless questions on here and elsewhere and cannot for the life of me figure out what I'm doing wrong. I'm trying to store an array of CGPoints as NSValues inside of an NSMutableArray named points like so on the iPhone: NSValue *point = [NSValue valueWithCGPoint:firstTouch]; NSLog(@"NSValue *point = %@", point); [...

Core Data - Breaking A Relationship

Hi, I have a Patient entity and a List entity. A Patient can belong to several different lists and a list can have several different patients. Say I have a patient who belongs to 3 lists (A, B, C). I want to remove the patient from lists A & B. I do not want to delete lists A & B themselves though obviously. How do I go about doing thi...

Best way to add a large chunk of text to a UIScrollView?

What is the best way to display a large chunk of text (taken from a .txt file in the app) in a UIScrollView so a user can scroll about it? Length of the text is variable. ...