Search Results

Search found 6745 results on 270 pages for 'objective c 2 0'.

Page 25/270 | < Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >

  • Objective-C NSString Assignment Problem

    - by golfromeo
    In my Cocoa application, in the header file, I declare a NSString ivar: NSString *gSdkPath; Then, in awakeFromNib, I assign it to a value: gSdkPath = @"hello"; Later, it's value is changed in the code: gSdkPath = [NSString stringWithString:[folderNames objectAtIndex:0]]; (the object returned from objectAtIndex is an NSString) However, after this point, in another method when I try to NSLog() (or do anything with) the gSdkPath variable, the app crashes. I'm sure this has something to do with memory management, but I'm beginning with Cocoa and not sure exactly how this all works. Thanks for any help in advance.

    Read the article

  • Objective-C ref count and autorelease

    - by turbovince
    Hey guys, suppose the following code: int main (int argc, const char * argv[]) { //[...] Rectangle* myRect = [[Rectangle alloc] init]; Vector2* newOrigin = [[[Vector2 alloc] init] autorelease]; // ref count 1 [newOrigin setX: 50.0f]; [myRect setOrigin: newOrigin]; // ref count 2 [myRect.origin setXY: 25.0f :100.0f]; // ref count goes to 3... why ? [myRect release]; [pool drain]; return 0; } Rectangle's origin is declared as a (retain) synthesized property. Just wondering 2 things: Why does ref count goes to 3 when using the getter accessor of Rectangle's origin? Am I doing something wrong ? With a ref count of 3, I don't understand how this snippet of code cannot leak. Calling release on myRect will make it go down to 2 since I call release on the origin in dealloc(). But then, when does autorelease take effect? Thanks!

    Read the article

  • objective-c having issues with an NSDictioary object

    - by Mark
    I have a simple iPhone app that Im learning and I want to have an instance variable called urlLists which is an NSDictionary I have declared it like so: @interface MyViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>{ IBOutlet UIPickerView *pickerView; NSMutableArray *categories; NSDictionary *urlLists; } @property(retain) NSDictionary *urlLists; @end and in the implementation: @implementation MyViewController @synthesize urlLists; ... - (void)viewDidLoad { [super viewDidLoad]; categories = [[NSMutableArray alloc] init]; [categories addObject:@"Sport"]; [categories addObject:@"Entertainment"]; [categories addObject:@"Technology"]; [categories addObject:@"Political"]; NSArray *objects = [NSArray arrayWithObjects:@"value1", @"value2", @"value3", @"value4", nil]; urlLists = [NSDictionary dictionaryWithObjects:objects forKeys:categories]; for (id key in urlLists) { NSLog(@"key: %@, value: %@", key, [urlLists objectForKey:key]); } } ... @end And, this all works up to here. I have added a UIPicker to my app, and when I select one of the items, I want to Log the one picked and its related entry in my dictionary. -(void) pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger) component { for (id key in self.urlLists) { NSLog(@"key: %@, value: %@", key, [urlLists objectForKey:key]); } } but I get the old EXC_BAD_ACCESS error... I know Im missing something small, but what? Thanks

    Read the article

  • Objective-C memory management issue

    - by Toby Wilson
    I've created a graphing application that calls a web service. The user can zoom & move around the graph, and the program occasionally makes a decision to call the web service for more data accordingly. This is achieved by the following process: The graph has a render loop which constantly renders the graph, and some decision logic which adds web service call information to a stack. A seperate thread takes the most recent web service call information from the stack, and uses it to make the web service call. The other objects on the stack get binned. The idea of this is to reduce the number of web service calls to only those appropriate, and only one at a time. Right, with the long story out of the way (for which I apologise), here is my memory management problem: The graph has persistant (and suitably locked) NSDate* objects for the currently displayed start & end times of the graph. These are passed into the initialisers for my web service request objects. The web service call objects then retain the dates. After the web service calls have been made (or binned if they were out of date), they release the NSDate*. The graph itself releases and reallocates new NSDates* on the 'touches ended' event. If there is only one web service call object on the stack when removeAllObjects is called, EXC_BAD_ACCESS occurs in the web service call object's deallocation method when it attempts to release the date objects (even though they appear to exist and are in scope in the debugger). If, however, I comment out the release messages from the destructor, no memory leak occurs for one object on the stack being released, but memory leaks occur if there are more than one object on the stack. I have absolutely no idea what is going wrong. It doesn't make a difference what storage symantics I use for the web service call objects dates as they are assigned in the initialiser and then only read (so for correctness' sake are set to readonly). It also doesn't seem to make a difference if I retain or copy the dates in the initialiser (though anything else obviously falls out of scope or is unwantedly released elsewhere and causes a crash). I'm sorry this explanation is long winded, I hope it's sufficiently clear but I'm not gambling on that either I'm afraid. Major big thanks to anyone that can help, even suggest anything I may have missed?

    Read the article

  • Can we send an two dimensional array as input for a function in Objective C.

    - by srikanth rongali
    I have data stored in two dimensional array. I want it to send in to a function in this way, I have written the following in another class. // do if( array[iTemp][1] != 10 ) { Enemy *enemyXX = [[Enemy alloc] init]; [enemyXX EnemyXXTarget: array[iTemp][1]]; iTemp++; }while( iTemp != 9); // -(void)EnemyXXTarget:(id)sender; is function declared in Enemy class. But is giving me an error error: incompatible type for argument 1 of 'EnemyXXTarget:' Where I am wrong ? Please help me. Thank You.

    Read the article

  • Minutia on Objective-C Categories and Extensions.

    - by Matt Wilding
    I learned something new while trying to figure out why my readwrite property declared in a private Category wasn't generating a setter. It was because my Category was named: // .m @interface MyClass (private) @property (readwrite, copy) NSArray* myProperty; @end Changing it to: // .m @interface MyClass () @property (readwrite, copy) NSArray* myProperty; @end and my setter is synthesized. I now know that Class Extension is not just another name for an anonymous Category. Leaving a Category unnamed causes it to morph into a different beast: one that now gives compile-time method implementation enforcement and allows you to add ivars. I now understand the general philosophies underlying each of these: Categories are generally used to add methods to any class at runtime, and Class Extensions are generally used to enforce private API implementation and add ivars. I accept this. But there are trifles that confuse me. First, at a hight level: Why differentiate like this? These concepts seem like similar ideas that can't decide if they are the same, or different concepts. If they are the same, I would expect the exact same things to be possible using a Category with no name as is with a named Category (which they are not). If they are different, (which they are) I would expect a greater syntactical disparity between the two. It seems odd to say, "Oh, by the way, to implement a Class Extension, just write a Category, but leave out the name. It magically changes." Second, on the topic of compile time enforcement: If you can't add properties in a named Category, why does doing so convince the compiler that you did just that? To clarify, I'll illustrate with my example. I can declare a readonly property in the header file: // .h @interface MyClass : NSObject @property (readonly, copy) NSString* myString; @end Now, I want to head over to the implementation file and give myself private readwrite access to the property. If I do it correctly: // .m @interface MyClass () @property (readonly, copy) NSString* myString; @end I get a warning when I don't synthesize, and when I do, I can set the property and everything is peachy. But, frustratingly, if I happen to be slightly misguided about the difference between Category and Class Extension and I try: // .m @interface MyClass (private) @property (readonly, copy) NSString* myString; @end The compiler is completely pacified into thinking that the property is readwrite. I get no warning, and not even the nice compile error "Object cannot be set - either readonly property or no setter found" upon setting myString that I would had I not declared the readwrite property in the Category. I just get the "Does not respond to selector" exception at runtime. If adding ivars and properties is not supported by (named) Categories, is it too much to ask that the compiler play by the same rules? Am I missing some grand design philosophy?

    Read the article

  • Objective-C stringWithFormat misses an argument?

    - by rocity
    When I run this code: - (NSString *)description{ return [NSString stringWithFormat:@"(FROG idle:%i animating:%i rect:%@ position:%@ tongue:%@)", self.idleTime, self.animating, NSStringFromCGRect(self.rect), NSStringFromCGPoint(self.position), tongue ]; } I get the following output: (FROG idle:0 animating:0 rect:(null) position:{{1,2}{3,4}} tongue:{5,6}) This is wrong because it seems to be skipping the rect format string and placing everything displaced by one. So idle and animating are what I expect, then rect is skipped, but the result from NSStringFromCGRect(self.rect) is placed into position, then the result for position is pushed to tongue, then tongue is not displayed at all. I'm at a loss.

    Read the article

  • Make sense of Notification Watcher source objective-c

    - by Chris
    From Notification Watcher source. - (void)selectNotification:(NSNotification*)aNotification { id sender = [aNotification object]; [selectedDistNotification release]; selectedDistNotification = nil; [selectedWSNotification release]; selectedWSNotification = nil; NSNotification **targetVar; NSArray **targetList; if (sender == distNotificationList) { targetVar = &selectedDistNotification; targetList = &distNotifications; } else { targetVar = &selectedWSNotification; targetList = &wsNotifications; } if ([sender selectedRow] != -1) { [*targetVar autorelease]; *targetVar = [[*targetList objectAtIndex:[sender selectedRow]] retain]; } if (*targetVar == nil) { [objectText setStringValue:@""]; } else { id obj = [*targetVar object]; NSMutableAttributedString *objStr = nil; if (obj == nil) { NSFont *aFont = [objectText font]; NSDictionary *attrDict = italicAttributesForFont(aFont); objStr = [[NSMutableAttributedString alloc] initWithString:@"(null)" attributes:attrDict]; } else { /* Line 1 */ objStr = [[NSMutableAttributedString alloc] initWithString: [NSString stringWithFormat:@" (%@)", [obj className]]]; [objStr addAttributes:italicAttributesForFont([objectText font]) range:NSMakeRange(1,[[obj className] length]+2)]; if ([obj isKindOfClass:[NSString class]]) { [objStr replaceCharactersInRange:NSMakeRange(0,0) withString:obj]; } else if ([obj respondsToSelector:@selector(stringValue)]) { [objStr replaceCharactersInRange:NSMakeRange(0,0) withString:[obj performSelector:@selector(stringValue)]]; } else { // Remove the space since we have no value to display [objStr replaceCharactersInRange:NSMakeRange(0,1) withString:@""]; } } [objectText setObjectValue:objStr]; /* LINE 2 */ [objStr release]; } [userInfoList reloadData]; } Over at //LINE 2 objStr is being released. Is this because we are assigning it with alloc in //LINE 1? Also, why is //LINE 1 not: objStr = [NSMutableAttributedString* initWithString:@"(null)" attributes:attrDict] If I create a new string like (NSString*) str = [NSString initWithString:@"test"]; ... str = @"another string"; Would I have to release str, or is this wrong and if I do that I have to use [[NSString alloc] initWithString:@"test"]? Why isn't the pointer symbol used as in [[NSString* alloc] ...? Thanks

    Read the article

  • Objective C: Compare timeInMillis with current time

    - by Srivathsan Canchi
    Hello, In my iPhone application, I need to calculate the time difference between the time a message was created on the server, and the time my phone received it. The server (Java) puts in a number returned by System.currentTimeMillis() as metadata along with the message. How do I compare this number with the current time on the device? Could not find a suitable NSDate method to do this comparison. Thanks in advance!

    Read the article

  • Regarding C Static/Non Static Float Arrays (Xcode, Objective C)

    - by user1875290
    Basically I have a class method that returns a float array. If I return a static array I have the problem of it being too large or possibly even too small depending on the input parameter as the size of the array needed depends on the input size. If I return just a float array[arraysize] I have the size problem solved but I have other problems. Say for example I address each element of the non-static float array individually e.g. NSLog(@"array[0] %f array[1] %f array[2] %f",array[0],array[1],array[2]); It prints the correct values for the array. However if I instead use a loop e.g. for (int i = 0; i < 3; i++) { NSLog(@"array[%i] %f",i,array[i]); } I get some very strange numbers (apart from the last index, oddly). Why do these two things produce different results? I'm aware that its bad practice to simply return a non static float, but even so, these two means of addressing the array look the same to me. Relevant code from class method (for non-static version)... float array[arraysize]; //many lines of code later if (weShouldStoreValue == true) { array[index] = theFloat; index = index + 1; } //more lines of code later return array; Note that it returns a (float*).

    Read the article

  • Objective-c for the iphone: Mystery memory leak

    - by user200341
    My application seems to have 4 memory leaks (on the device, running instruments). The memory leaks seems to come from this code: NSURL *url = [self getUrl:destination]; [destination release]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [url release]; [request setHTTPMethod:@"GET"]; [request addValue:@"application/json" forHTTPHeaderField:@"content-type"]; NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self]; [request release]; [connection release]; I am releasing all my objects as far as I can see but it's still showing this as the source of the 4 memory leaks. This is on the Device running 3.1.3 Is it acceptable to have a few memory leaks in your app or do they all have to go?

    Read the article

  • Simplifying loop in Objective-C

    - by Joe Habadas
    I have this enormous loop in my code (not by choice), because I can't seem to make it work any other way. If there's some way make this simple as opposed to me repeating it +20 times that would be great, thanks. for (NSUInteger i = 0; i < 20; i++) { if (a[0] == 0xFF || b[i] == a[0]) { c[0] = b[i]; if (d[0] == 0xFF) { d[0] = c[0]; } ... below repeats +18 more times with [i+2,3,4,etc] ... if (a[1] == 0xFF || b[i + 1] == a[1]) { c[1] = b[i + 1]; if (d[1] == 0xFF) { d[1] = c[1]; } ... when it reaches the last one it calls a method ... [self doSomething]; continue; i += 19; ... then } repeats +19 times (to close things)... } } } I've tried almost every possible combo of things that I know of attempting to make this smaller and efficient. Take a look at my flow chart — pretty huh? i'm not a madman, honest.

    Read the article

  • Duplicate Method Names - Objective-c

    - by evanchri
    Why does this compile with out any errors or warnings? @interface ObjectTest : NSObject { } -(void)iAmADoubleMethod; -(void)iAmADoubleMethod; @end @implementation ObjectTest -(void)iAmADoubleMethod { NSLog(@"IAmADoubleMethod"); } @end I came across this in a project I am working on. I come from a C++ background, so I figure I would get at least a warning for this. Not only would I like to know why it complies but could this code cause any problems? Thanks.

    Read the article

  • Converting &amp; to & in Objective-C

    - by nbojja
    Hi All, I have a URL string in the following format. http://myserver.com/_layouts/feed.aspx?xsl=4&amp;web=%2F&amp;page=dda3fd10-c776-4d69-8c55-2f1c74b343e2&amp;wp=476f174a-82df-4611-a3df-e13255d97533 I want to replace &amp; with & in the above URL. My result should be: http://myserver.com/_layouts/feed.aspx?xsl=4&web=%2F&page=dda3fd10-c776-4d69-8c55-2f1c74b343e2&amp;wp=476f174a-82df-4611-a3df-e13255d97533 Can someone post me the code to get this done? Thanks

    Read the article

  • Print out the variable name objective-C

    - by vodkhang
    Continued from the last question here: Log method name in Obj-C . I just wondered if there is a way to print out the variable name as well. For example: NSString *name = "vodkhang"; NCLog(@"%@", name); and I hope that the output should be: name: vodkhang Just to summarize the previous post, currently, I can print out the class name, method name and the line number when I call NCLog(@"Hello World"); <ApplicationDelegate:applicationDidFinishLaunching:10>Hello world with #define NCLog(s, ...) NSLog(@"<%@:%d> %@", __FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])

    Read the article

  • UIGraphicsBeginImageContext question in Objective C

    - by Henry D'Andrea
    I need the UIGraphicsBeginImageContext(self.view.frame.size); changed to where the .frame part pulls from webView - (void) save { UIGraphicsBeginImageContext(self.view.frame.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); NSLog(@"TEST"); } WEBVIEW CODE: -(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)ntype { NSLog(@"Scheme: %@", request.URL.scheme); if ([request.URL.scheme isEqualToString:@"save"]) { [self save]; } return true; }

    Read the article

  • Isn't objective-c function parameter syntax weird? [closed]

    - by Haoest
    Consider the following method: +(void) myMethod:(int)arg1 **argument2**(int)arg2 **argument3**(int) arg3; See how the first argument, unlike the 2nd and 3rd, doesn't have a description, giving it an impression of bad symmetry. Also you would expect the extra typing will provide named argument as you pass it in, but you still have to pass them in the correct order. Can anyone help me make sense of this?

    Read the article

  • Accessing elements from an array in objective c

    - by James
    I am trying to access individual elements of my array. This is an example of the contents of the array i am trying to access. <City: 0x4b77fd0> (entity: Spot; id: 0x4b7e580 <x-coredata://D902D50B-C945-42E2-8F71-EDB62222C0A7/Spot/p5> ; data: { CityToProvince = 0x4b7dbd0 <x-coredata://D902D50B-C945-42E2-8F71-EDB62222C0A7/County/p15>; Description = "Friend"; Email = "[email protected]"; Age = 21; Name = "Adam"; Phone = "+44175240"; }), The elements i am trying to access are Name, Phone, etc ... How would i go about doing this?

    Read the article

  • How to create a NSAutoreleasePool without Objective-C?

    - by fbafelipe
    I have multiplatform game written in C++. In the mac version, even though I do not have any obj-c code, one of the libraries I use seems to be auto-releasing stuff, and I get memory leaks for that, since I did not create a NSAutoreleasePool. What I want is to be able to create (and destroy) a NSAutoreleasePool without using obj-c code, so I don't need to create a .m file, and change my build scripts just for that. Is that possible? How can that be done? OBS: Tagged C and C++, because a solution in any of those languages will do.

    Read the article

  • Objective C: Class Extensions and Protocol Conformation Warnings

    - by Ben Reeves
    I have a large class, which I have divided into several different class extension files for readability. @protocol MyProtocol @required -(void)required; @end @interface MyClass : NSObject <MyProtocol> @end @interface MyClass (RequiredExtension) -(void)required; @end Is there a better way to do this, without the compiler warning? warning: class 'MyClass' does not fully implement the 'MyProtocol' protocol

    Read the article

  • objective c import once

    - by joels
    I have a header file with a bunch on statics like static NSString * SOME_NAME = @"someMeaning"; What is the best way to import this? Should I define them some other way? I tried just using the #import statement but any file that imports it gives me a warning saying SOME_NAME defined but not used...

    Read the article

  • Objective-C(iPhone SDK) - Code for Chemical Equation Balancer help

    - by Evan
    -(IBAction) balancer: (id) sender{ double M[4][4]; M[0][0] = 6.0; M[0][1] = 0.0; M[0][2] = -1.0; M[0][3] = 0.0; M[1][0] = 12.0; M[1][1] = 0.0; M[1][2] = 0.0; M[1][3] = 2.0; M[2][0] = 6.0; M[2][1] = 2.0; M[2][2] = -2.0; M[2][3] = 1.0; M[3][0] = 0.0; M[3][1] = 0.0; M[3][2] = 0.0; M[3][3] = 0.0; int rowCount = 4; int columnCount = 4; int lead = 0; for (int r = 0; r < rowCount; r++) { if (lead = columnCount) break; int i = r; while (M[i][lead] == 0) { i++; if (i == rowCount) { i = r; lead++; if (lead == columnCount){ break; } } } double temp[4] ; temp[0] = M[r][0]; temp[1] = M[r][1]; temp[2] = M[r][2]; temp[3] = M[r][3]; M[r][0] = M[i][0]; M[r][1] = M[i][1]; M[r][2] = M[i][2]; M[r][3] = M[i][3]; M[i][0] = temp[0]; M[i][1] = temp[1]; M[i][2] = temp[2]; M[i][3] = temp[3]; double lv = M[r][lead]; for (int j = 0; j < columnCount; j++) M[r][j] = M[r][j] / lv; for (int f = 0; f < rowCount; f++) { if (f != r) { double l = M[f][lead]; for (int j = 0; j < columnCount; j++) M[f][j] = M[f][j] - l * M[r][j]; } } lead++; } NSString* myNewString = [NSString stringWithFormat:@"%g",M[0][3]]; label1.text = myNewString; } This is returning NaN, while it should be returning .16666667 for M[0][3]. Any suggestions on how to fix this?

    Read the article

  • Objective-C Definedness

    - by Dan Ray
    This is an agonizingly rookie question, but here I am learning a new language and framework, and I'm trying to answer the question "What is Truth?" as pertains to Obj-C. I'm trying to lazy-load images across the network. I have a data class called Event that has properties including: @property (nonatomic, retain) UIImage image; @property (nonatomic, retain) UIImage thumbnail; in my AppDelegate, I fetch up a bunch of data about my events (this is an app that shows local arts event listings), and pre-sets each event.image to my default "no-image.png". Then in the UITableViewController where I view these things, I do: if (thisEvent.image == NULL) { NSLog(@"Going for this item's image"); UIImage *tempImage = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString: [NSString stringWithFormat: @"http://www.mysite.com/content_elements/%@_image_1.jpg", thisEvent.guid]]]]; thisEvent.image = tempImage; } We never get that NSLog call. Testing thisEvent.image for NULLness isn't the thing. I've tried == nil as well, but that also doesn't work.

    Read the article

< Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >