objective-c-2.0

Returning from method inside a @synchronized block

I'd just like to know if it's advised to return from a method within a @synchronized block? For example: - (id)test { @synchronized(self) { if (a) return @"A"; else return @"B"; } } As opposed to: - (id)test { NSString *value; @synchronized(self) { if (a) value = @"A"; else value = @"B"; } re...

Setting shadowColor with property syntax gives compiler error: Expected identifier before '[' token.

I have an iPad app in which I'm setting the shadow color of a UILabel in a UIView's initWithFrame: method. When I use the following syntax: m_label.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.5]; I get this compiler error: Expected identifier before '[' token However, when I use the following syntax: [m_label setShadowColor:[...

Different results coming out of an init method than those expected. Why does this happen and how can I correct it?

When I run this method the two properties I have are set to (NULL) when I try and access them outside of the if statement. But they are set to 0 and NO if I check them inside the if statement. -(id) init { NSLog(@"Jumping into the init method!"); if (self = [super init]) { NSLog(@"Running the init method extras"...

Loading...Please wait for UIWebView - iPhone

Hi guys, In Safari and other browsers, there is a bar that would indicate the percentage of the loading progress, and I, myself, trying to implement something similiar on iPhone, when loading some content in UIWebView, I would like the app to indicate the percentage of the page being loaded. I tried some google search and realize we c...

core-plot barchart does not work!!

Hello~ I try to draw bar chart!! numberForPlot is not good work, only CPBarPlotFieldBarLength set. -(NSNumber *)numberForPlot: (CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index { NSDecimalNumber *num = nil; NSString *key = (fieldEnum == CPScatterPlotFieldX) ? @"x" : @"y"; if ( [plot isKindOfClass:[C...

Problem with Function to convert UNIX TimeStamp

I get those two errors: - Can not use an object as parameter to a method - Incompatible types in return That's my code: - (NSString) dateStringFromUnixTimeStamp:(NSInteger)timeStamp { //Create Date-String from UNIX-Time-Stamp: NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp]; NSDateComponents *monthComponents = [[NSC...

Custom getter side-effects

Are there side-effects to calling a custom getter with dot notation? I had been using a synthesized getter in Objective-C via the dot notation, i.e. tree.fruitnumber returned the number of fruits in tree. I had to customize the getter (for reasons not pertinent to this question). I wrote it as -(int) fruitnumber { //climb into tr...

What is the point of @property and @synthesize?

I haven't been able to figure it out, and there are no websites which explain it clearly enough... what exactly are the purposes of @property and @synthesize? Thanks in advance! ...

How to get indexPath from one class to another

I have an app where my primary view is a tableview. where each cell loads another view containing certain data. Now, each cell is different so the data in the view loaded by each cell should be different. For that I need the indexPath. I've created a class for the TableView and another class for a simple UIView. How do I forward the inde...

Is object free / freed on dealloc and / or release?

I recently took an objective-c test to see how I would do. Turns out my score wasn't anywhere near as good as I hoped. That means more studying. During the test, I was asked this question: How do you free an object? A. [obj dealloc]; B. [obj release]; C. None of the above My choice was A, and I don't know if it's correct. The ques...

Why Objective-C properties are sort of inconvenient?

It is more of a complain than a question, though maybe someone has some good points on it. So basically if you want an ivar in your Objective-C class have accessor-methods you have to mention it 3 times SomeClass* _ivar; @property (nonatomic,retain/assign/copy) SomeClass* ivar; @synthesize ivar = _ivar; and maybe 4th time in dealloc m...

What's the purpose of an ivar when a property exists?

The following doesn't complain at compilation nor runtime about no name ivar. So why is it so common to see an ivar and @property/@synthesize. @interface PropTest : NSObject { } @property (retain) NSString *name; @end @implementation PropTest @synthesize name; @end int main (int argc, const char * argv[]) { NSAutoreleasePool * pool ...

Problem with small numbers in Objective C 2.0

I created a calculator class that does basic +,-, %, * and sin, cos, tan, sqrt and other math functions. I have all the variables of type double, everything is working fine for big numbers, so I can calculate numbers like 1.35E122, but the problem is with extremely small numbers. For example if I do calculation 1/98556321 I get 0 where ...

Using substringFromIndex on NSMutableString

Hey all Why is substringFromIndex not working for my NSMutableString? Here code similar to what I have: NSMutableString *myString = [[NSMutableString alloc] initWithString:@"This is my String"]; [myString substringFromIndex:5 NSLog(@"myString = %@", myString); //will output This is my String If I use substringFromIndex on NSString...

iphone: message sent to deallocated instance

Hi guys, i got a problem, if I run this code: NSString *xml = [[NSString alloc] init]; xml=[NSString stringWithFormat:@"<%@>", @"msg"]; NSLog(@"%@\n",xml); [xml release]; I got: 2010-09-07 11:45:15.523 test[1312:207] <msg> 2010-09-07 11:45:15.527 test[1312:207] *** -[CFString release]: message sent to deallocated instance 0x3d52ba...

How to click a checkbox in nstableview and update an object using KVC? Still a problem...

Hi all. A few days ago I posted a problem with using checkboxes in nstableview (old question). Peter Hosey helped me, but I am still unable to get this to work. I seem to be doing something very wrong with implementing a button that shoud be straightforward. I have a tableview with three fields; bool, text, and text. The values of each c...

iPhone App replace images

Hi all, I got a little problem. I use some images in my app. Today I wanted to replace them with new ones. But when I build and run the project I still get the old ones. I tried to touch the project and the new images but nothing seems to work. I deleted all references and files and imported the new images, but I still see just the old ...

scan string using nsscanner class

hi, I want to scan this string "hello I am emp 1313 object of string class 123" so in this I want to know if their are any integer value present and if present I want to display them for this I am using the NSScanner class and heres a view of my code NSString *str = @" hello I am emp 1313 object of string class 123"; NSString *l...

Casting of objects to dynamic types at runtime

I have the following code: + (UITableViewCell *) createTableViewCell: (NSString *) cell_id withTableView: tableView { SomeViewClass *cell = (SomeViewClass *)[tableView dequeueReusableCellWithIdentifier: cell_id]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed: @"AViewCell" ...

Objective C small syntax clarification

Hi, I have seen this code in most of the time. Here there are two variable names defined and in the implementation it synthesizing by assigning. Whats the purpose of doing some thing like this? Like keeping 2 separate variable names. Is this sort of a convention? Test.h @interface Test { id<something> _variable1; } @property (nona...