Search Results

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

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

  • 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

  • Objective-C and Cocoa : crash when calling a class function without entering the function

    - by Oliver
    Hello, I have a class function (declared and implemented) in a class MyUtils : + (NSString*) theFunction:(NSString*)param1 param2:(NSString*)param2 param3:(NSString*)param3; When I call this function, with : NSString *item = [MyUtils theFunction:@"abc" param2:aPreviousNSString param3:@"xyz"; my app crashes. In the debugger I have a breakpoint on the first action of the "theFunction" function. And this breakpoint is never reached. If I replace the call by NSString *item = @"youyou"; then everything is ok. Forcing a retain on aPreviousNSString before the call does not change anything. Do you have an idea of what is happening ? Thanks

    Read the article

  • Proper Memory Management for Objective-C Method

    - by Justin
    Hi, I'm programming an iPhone app and I had a question about memory management in one of my methods. I'm still a little new to managing memory manually, so I'm sorry if this question seems elementary. Below is a method designed to allow a number pad to place buttons in a label based on their tag, this way I don't need to make a method for each button. The method works fine, I'm just wondering if I'm responsible for releasing any of the variables I make in the function. The application crashes if I try to release any of the variables, so I'm a little confused about my responsibility regarding memory. Here's the method: FYI the variable firstValue is my label, it's the only variable not declared in the method. -(IBAction)inputNumbersFromButtons:(id)sender { UIButton *placeHolderButton = [[UIButton alloc] init]; placeHolderButton = sender; NSString *placeHolderString = [[NSString alloc] init]; placeHolderString = [placeHolderString stringByAppendingString:firstValue.text]; NSString *addThisNumber = [[NSString alloc] init]; int i = placeHolderButton.tag; addThisNumber = [NSString stringWithFormat:@"%i", i]; NSString *newLabelText = [[NSString alloc] init]; newLabelText = [placeHolderString stringByAppendingString:addThisNumber]; [firstValue setText:newLabelText]; //[placeHolderButton release]; //[placeHolderString release]; //[addThisNumber release]; //[newLabelText release]; } The application works fine with those last four lines commented out, but it seems to me like I should be releasing these variables here. If I'm wrong about that I'd welcome a quick explanation about when it's necessary to release variables declared in functions and when it's not. Thanks.

    Read the article

  • Javascript style objects in Objective-C

    - by awolf
    Background: I use a ton of NSDictionary objects in my iPhone and iPad code. I'm sick of the verbose way of getting/setting keys to these state dictionaries. So a little bit of an experiment: I just created a class I call Remap. Remap will take any arbitrary set[VariableName]:(NSObject *) obj selector and forward that message to a function that will insert obj into an internal NSMutableDictionary under the key [vairableName]. Remap will also take any (zero argument) arbitrary [variableName] selector and return the NSObject mapped in the NSMutableDictionary under the key [variableName]. e.g. Remap * remap = [[Remap alloc] init]; NSNumber * testNumber = [NSNumber numberWithInt:46]; [remap setTestNumber:testNumber]; testNumber = [remap testNumber]; [remap setTestString:@"test string"]; NSString * testString = [remap testString]; NSMutableDictionary * testDict = [NSMutableDictionary dictionaryWithObject:testNumber forKey:@"testNumber"]; [remap setTestDict:testDict]; testDict = [remap testDict]; where none of the properties testNumber, testString, or testDict are actually defined in Remap. The crazy thing? It works... My only question is how can I disable the "may not respond to " warnings for JUST accesses to Remap? P.S. : I'll probably end up scrapping this and going with macros since message forwarding is quite inefficient... but aside from that does anyone see other problems with Remap? Here's Remap's .m for those who are curious: #import "Remap.h" @interface Remap () @property (nonatomic, retain) NSMutableDictionary * _data; @end @implementation Remap @synthesize _data; - (void) dealloc { relnil(_data); [super dealloc]; } - (id) init { self = [super init]; if (self != nil) { NSMutableDictionary * dict = [[NSMutableDictionary alloc] init]; [self set_data:dict]; relnil(dict); } return self; } - (void)forwardInvocation:(NSInvocation *)anInvocation { NSString * selectorName = [NSString stringWithUTF8String: sel_getName([anInvocation selector])]; NSRange range = [selectorName rangeOfString:@"set"]; NSInteger numArguments = [[anInvocation methodSignature] numberOfArguments]; if (range.location == 0 && numArguments == 4) { //setter [anInvocation setSelector:@selector(setData:withKey:)]; [anInvocation setArgument:&selectorName atIndex:3]; [anInvocation invokeWithTarget:self]; } else if (numArguments == 3) { [anInvocation setSelector:@selector(getDataWithKey:)]; [anInvocation setArgument:&selectorName atIndex:2]; [anInvocation invokeWithTarget:self]; } } - (NSMethodSignature *) methodSignatureForSelector:(SEL) aSelector { NSString * selectorName = [NSString stringWithUTF8String: sel_getName(aSelector)]; NSMethodSignature * sig = [super methodSignatureForSelector:aSelector]; if (sig == nil) { NSRange range = [selectorName rangeOfString:@"set"]; if (range.location == 0) { sig = [self methodSignatureForSelector:@selector(setData:withKey:)]; } else { sig = [self methodSignatureForSelector:@selector(getDataWithKey:)]; } } return sig; } - (NSObject *) getDataWithKey: (NSString *) key { NSObject * returnValue = [[self _data] objectForKey:key]; return returnValue; } - (void) setData: (NSObject *) data withKey:(NSString *)key { if (key && [key length] >= 5 && data) { NSRange range; range.length = 1; range.location = 3; NSString * firstChar = [key substringWithRange:range]; firstChar = [firstChar lowercaseString]; range.length = [key length] - 5; // the 4 we have processed plus the training : range.location = 4; NSString * adjustedKey = [NSString stringWithFormat:@"%@%@", firstChar, [key substringWithRange:range]]; [[self _data] setObject:data forKey:adjustedKey]; } else { //assert? } } @end

    Read the article

  • Objective - C, fastest way to show sequence of images in UIImageView

    - by Almas Adilbek
    I have hundreds of images, which are frame images of one animation (24 images per second). Each image size is 1024x690. My problem is, I need to make smooth animation iterating each image frame in UIImageView. I know I can use animationImages of UIImageView. But it crashes, because of memory problem. Also, I can use imageView.image = [UIImage imageNamed:@""] that would cache each image, so that the next repeat animation will be smooth. But, caching a lot of images crashed app. Now I use imageView.image = [UIImage imageWithContentsOfFile:@""], which does not crash app, but doesn't make animation so smooth. Maybe there is a better way to make good animation of frame images? Maybe I need to make some preparations, in order to somehow achieve better result. I need your advices. Thank you!

    Read the article

  • Generating authentication header from azure table through objective-c

    - by user923370
    I'm fetching data from iCloud and for that I need to generate a header (azure table storage). I used the code below for that and it is generating the headers. But when I use these headers in my project it is showing "make sure that the value of authorization header is formed correctly including the signature." I googled a lot and tried many codes but in vain. Can anyone kindly please help me with where I'm going wrong in this code. -(id)generat{ NSString *messageToSign = [NSString stringWithFormat:@"%@/%@/%@", dateString,AZURE_ACCOUNT_NAME, tableName]; NSString *key = @"asasasasasasasasasasasasasasasasasasasasas=="; const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding]; const char *cData = [messageToSign cStringUsingEncoding:NSUTF8StringEncoding]; unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC); NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)]; NSString *hash = [Base64 encode:HMAC]; NSLog(@"Encoded hash: %@", hash); NSURL *url=[NSURL URLWithString: @"http://my url"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request addValue:[NSString stringWithFormat:@"SharedKeyLite %@:%@",AZURE_ACCOUNT_NAME, hash] forHTTPHeaderField:@"Authorization"]; [request addValue:dateString forHTTPHeaderField:@"x-ms-date"]; [request addValue:@"application/atom+xml, application/xml"forHTTPHeaderField:@"Accept"]; [request addValue:@"UTF-8" forHTTPHeaderField:@"Accept-Charset"]; NSLog(@"Headers: %@", [request allHTTPHeaderFields]); NSLog(@"URL: %@", [[request URL] absoluteString]); return request; } -(NSString*)rfc1123String:(NSDate *)date { static NSDateFormatter *df = nil; if(df == nil) { df = [[NSDateFormatter alloc] init]; df.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]; df.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; df.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'"; } return [df stringFromDate:date]; }

    Read the article

  • How to set an image based on iphone platform in objective-c

    - by Toran Billups
    I'm moving my application from 3.x to 4.x as I prepare for the app store and found that I need to have 2 copies of all my custom pngs - my question is how can I determine what img to show and when. Example - how do I know to show the Find.png vs the [email protected] Is it "safe" or "correct" to look for 4.x specific apis or does the iphone have a way to determine what platform you are on at runtime? Thank you in advance

    Read the article

  • Inserting a line break from a variable objective c

    - by user337174
    I am pulling data into my iphone application using xml. The xml value is then placed in a variable. example variable: 123 London road \n London \n England The variable is then set as a label. I want the line breaks to appear in the label, instead it is printing \n. If i manually set the label value locationLabel.text = @"123 London road \n London \n England" It works as i want it to. Can anyone explain this?

    Read the article

  • Don't understand multiple parameter declarations in objective-c

    - by Blankman
    can someone clarify this for me: When there’s more than one argument, the arguments are declared within the method name after the colons. Arguments break the name apart in the declaration, just as in a message. For example: - (void)setWidth:(float)width height:(float)height; So in the above: method is for instance variables returns void parameter#1 is a float, named width. parameter#2 is a float,named height. But why is it hieght:(float)height; and not just: - (void)setWidth: (float)width (float)height;

    Read the article

  • Make a call in Objective C help!

    - by Henry D'Andrea
    I need to make a call where it says add call here. Can someone help? (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)ntype { NSLog(@"Scheme: %@", request.URL.scheme); if ([request.URL.scheme isEqualToString:@"save"]) { //Add Call here } return true; } FROM this code- (void) save { UIGraphicsBeginImageContext(self.view.frame.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); NSLog(@"TEST"); }

    Read the article

  • Objective C iPhone performance issue

    - by Asad Khan
    Ok guys I am developing an iPhone app I have a Model class which follows a Singleton design pattern. Now I have an NSArray in it which is initialized to around some 1000 NSStrings in the init method. Now I need to use this data in some view controller. so I import Model.h, I create an array of NSString objects in view controller & set the data to it. But now the problem is that now I have 2000 NSStrings currently allocated, which I believe is not a good thing on iPhone due to memory considerations. releasing model object wont help because I've overrided release method to release nothing according to the pattern & I cannot change the design now because now a lot of code works on the assumption of model being a singleton. & in future maybe the initial NSStrings may grow to 2000 or even more & then I'll have 4000 NSStrings allocated at one time .... I am a little confused on how to go about it any suggestions

    Read the article

  • Objective C instance variables - Newbie

    - by Dwayne King
    OK - so I'm sure my confusion here is just a result of being stuck in a "Java mindset" and not understanding how Obj C differs in this case. In Java, I can declare a variable in a class, like this, and each instance of that class will have it's own: MyClass { String myVar; MyClass() { // constructor } } In Obj C I tried to do the same thing by declaring a variable only in the .m file like this: #import "MyClass.h" @implementation MyClass NSString *testVar; @end My expectation here was that this variable has a scope limited to this class. So I created a second class (identical): #import "MySecondClass.h" @implementation MySecondClass NSString *testVar; @end What I'm seeing (and has me baffled) is that changing the variable in one class, affects the value seen in the other class. In fact, if I set a breakpoint, and then "Jump to Definition" of the variable, it takes me to th I've created an extremely small XCode project that demonstrates the problem here Nothing more humbling than moving to a new language :) Thanks in advance.

    Read the article

  • static NSStrings in Objective-C

    - by MikeyWard
    I frequently see a code snippet like this in class instance methods: static NSString *myString = @"This is a string."; I can't seem to figure out why this works. Is this simply the objc equivalent of a #define that's limited to the method's scope? I (think) I understand the static nature of the variable, but more specifically about NSStrings, why isn't it being alloc'd, init'd? Thanks~

    Read the article

  • Objective-C++ visibility question

    - by John Smith
    I have linked a library with my program. It works fine. The only problem is that there visibility errors/warnings (thousands of them). They are all of the form: newlib::method() has different visibility (default) in newlib.a and (hidden) in AppDelegate.o It is always with AppDelegate.o. I have tried to set the visibility for both the library and the main app in several ways: the visibility checkmark in XCode, and -fvisibility. Non seem to have worked. Is there somethin special about AppDelegate.mm?

    Read the article

  • Passing a pointer to a function in objective-c

    - by Chiodo
    Hi, i've a stupid questiona about passing pointer. I've this: @interface MyClass : NSObject myobj* foo; -(void)doSomething:(myobj*)aObj; @end @implementation MyClass -(void)doSomething:(myobj*)aObj { cFuncCall(&aObj); //alloc memory and init the object } -(id)init { //init stuff... [self doSomething:foo]; // foo retun 0x0!!! } @end why foo return nil??? It should be initialized by cFuncCall!

    Read the article

  • Objective-C Objects Having Each Other as Properties

    - by mwt
    Let's say we have two objects. Furthermore, let's assume that they really have no reason to exist without each other. So we aren't too worried about re-usability. Is there anything wrong with them "knowing about" each other? Meaning, can each one have the other as a property? Is it OK to do something like this in a mythical third class: Foo *f = [[Foo alloc] init]; self.foo = f; [f release]; Bar *b = [[Bar alloc] init]; self.bar = b; [b release]; foo.bar = bar; bar.foo = foo; ...so that they can then call methods on each other? Instead of doing this, I'm usually using messaging, etc., but sometimes this seems like it might be a tidier solution. I hardly ever see it in example code (maybe never), so I've shied away from doing it. Can somebody set me straight on this? Thanks.

    Read the article

  • Objective C: Why is this code leaking?

    - by Johnny Grass
    I'm trying to implement a method similar to what mytunescontroller uses to check if it has been added to the app's login items. This code compiles without warnings but if I run the leaks performance tool I get the following leaks: Leaked Object # Address Size Responsible Library Responsible Frame NSURL 7 < multiple > 448 LaunchServices LSSharedFileListItemGetFSRef NSCFString 6 < multiple > 432 LaunchServices LSSharedFileListItemGetFSRef Here is the responsible culprit: - (BOOL)isAppStartingOnLogin { LSSharedFileListRef loginListRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL); if (loginListRef) { NSArray *loginItemsArray = (NSArray *)LSSharedFileListCopySnapshot(loginListRef, NULL); NSURL *itemURL; for (id itemRef in loginItemsArray) { if (LSSharedFileListItemResolve((LSSharedFileListItemRef)itemRef, 0, (CFURLRef *) &itemURL, NULL) == noErr) { if ([[itemURL path] hasPrefix:[[NSBundle mainBundle] bundlePath]]) { [loginItemsArray release]; CFRelease(loginListRef); return YES; } } } [loginItemsArray release]; CFRelease(loginListRef); } return NO; }

    Read the article

  • Objective C memory leaking

    - by Jakub Lédl
    Hi everyone, I'm creating one Cocoa application for myself and I found a problem. I have two NSTextFields and they're connected to each other as nextKeyViews. When I run this app with memory leaks detection tool and tab through those 2 textboxes for a while, enter some text etc., I start to leak memory. It shows me that the AppKit library is responsible, the leaked objects are NSCFStrings and the responsible frames are [NSEvent charactersIgnoringModifiers] and [NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]. I know this is quite a brief and incomplete description, but does anyone have any ideas what could be the problem? Also, I don't use GC, so I release my instance variables in the controllers dealloc. What about the outlets? Since IBOutlet is just a mark for Interface Builder and doesn't actually mean anything, should I release them too?

    Read the article

  • Objective-C retain counts clarification

    - by Tom
    Hey, I kind of understand what's retain counts for. But not totally. I looked on google a lot to try to understand but still I don't. And now I'm in a bit of code (I'm doing iPhone development) that I think I should use them but don't know totally how. Could someone give me a quick and good example of how and why using them? Thanks!

    Read the article

  • I need objective-C syntax for calculating bmi

    - by Umaid
    Actually I am working on bmi calculator. Where I would like to calculate bmi for height in inches and weight in lbs and also in need of correct formula for height in cm and weight in kgs. I have tried but couldn't calculate actual value coming withing the range as below. It exceeds the range. BMI Categories: * Underweight = <18.5 * Normal weight = 18.5-24.9 * Overweight = 25-29.9 * Obesity = BMI of 30 or greater

    Read the article

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