objective-c,automatic-ref-countingRelated issues-Collection of common programming errors


  • anonymous
    iphone objective-c ios xcode
    I have uiscrollview with some buttons in it. I want to make one particular button to glow.I made glowing-pulsating effect of button with following code:(button in UIView)- (IBAction)selectChampionAction:(id)sender{if ( self.timer ) {// Stop timer[self.timer invalidate];self.timer = nil;// Workaround: we have to return the layer’s delegate property to what it was// Otherwise, we will encounter an unexpected resultself.viewForGlowing.layer.delegate = self.viewForGlowing;} else {// Woraround: UIVie

  • doctordoder
    objective-c arrays xcode pointers opengl
    Following this thread, I saw an alternative way to initialize the values of an array which works for my situation. I can’t use the standard float *simpleArray = {1.0f, 2.0f} because this array needs to be have global scope, and it also needs to be initialized after several variables that can’t be initialized at the global-level (object pointers). I tried implementing one method from the thread like this on a simpler example which doesn’t involve a second array.float *simpleArray = malloc(_numVer

  • Optimus
    objective-c json web-services
    I’m new in ios development. I’m developing an app which consuming soap web services and I’m facing a problem now The method in webservice return value as json string but it look like xml data which is given below <?xml version=”1.0″ encoding=”utf-8″?> <string xmlns=”http://tempuri.org/”>[“data”1,”data”2,”data”3,”data”4]</string>because of that I cant convert the json to NSArray using SBJSONParser when I’m trying to parse it showing the following error-JSONValue failed. Error i

  • Kyle Decot
    ios objective-c sprite-kit game-physics
    I am having a problem when trying to put two blocks that have physics bodies on top of one another.http://s1173.photobucket.com/user/Kyle_Decot/media/example_zps02f027fe.mp4.htmlAs you can see in the video I am able to place my block on top of the stacked blocks even though they are placed right on top of one another.Both the player block and the other blocks inherit from a base Block class which looks like this#import “Block.h”@implementation Block+ (void)loadSharedAssets {}- (id)initWithColor:

  • OpenLearner
    objective-c
    I have this line:NSString *objectkey=[NSString stringWithFormat:@”%@”,[line objectAtIndex:1]];If objectAtIndex:0, it works fine. But if 1, it produces SIGABRT error at runtime.However, I have another line to confirm that the array “line” has an object at index 1:NSLog(@”%d”,[line count]);This returns 2 to the console.Why would SIGABRT occur even though an index should exist there?As for line, it is created like this:for (int i=1;i<=[components count];i++){NSArray*line=[[components objectAtInd

  • mightee.cactus
    ios objective-c uitableview pstcollectionview
    In the app I develop I have a bunch of tiles (PSTCollectionView) on the screen. When user clicks on one cell he gets moved to another controller by calling segue programmatically. To avoid clicking cell several times at a time I add transparent overlay right after cell click that should prevent clicking at any collection tile.Everything seemed to go well until I run it on iPad 1: in some cases device hangs a bit and overlay appears a bit late which leads to the situation that allows user to clic

  • Aaron Brager
    ios objective-c core-animation calayer quartz-graphics
    On iOS, I am adding a CALayer to a UITableViewCell’s layer. This is my first time using CALayer, and it is simply supposed to change the background color of the table cell. My goal is (1) to learn how to use CALayer, and (2) to test using Instruments whether the drawing is faster than my current implementation, which slows down on CGContextFillRect.(Technical Q&A QA1708 was the catalyst for all this.)Current Implementation (works)- (void)drawRect:(CGRect)r {UIColor *myColor = [self someCol

  • ChrisHeneghan
    objective-c xcode xcode4
    I’ve just started to learn objective c and I was playing around with typedef, enumerations, switch statements, and functions, just to become more familiar with them. From my understanding, this code should all work, but I get a compile error on where I declare the switch statement that says “unexpected type name ‘dinnerPreference’: expected expression. If I used typedef to define dinnerPreference, then why does this happen.typedef enum { pizza = 0, steak = 1, seafood = 2} dinnerPreference; int

  • NSGod
    objective-c osx cocoa nstableview nsscrollview
    I have an issue with tableview scrolling. I have dragged a scrollview in to the xib with the frame. And I am creating a tableview programmatically and adding this to the scrollview as follows:NSRect frame = [[ScrollView contentView] bounds]; rTableView = [[MTableView alloc] initWithFrame:frame];MTableView is my custom class inheriting NSTableView and in the constructor, I am adding columns to the table view.[ScrollView setDocumentView: resultsTableView]; [ScrollView setHasVerticalScroller:YES];

  • Fábio Oliveira
    ios objective-c ios7 uistoryboardsegue
    I just encountered a problem with an app I bug-tested. I was banging my head to the wall to understand why I got this error:2013-11-25 09:02:55.687[186:60b] nested push animation can result in corrupted navigation bar 2013-11-25 09:02:56.055[186:60b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted. 2013-11-25 09:02:57.666[186:60b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Can’t add self as s

  • Ramshad
    iphone objective-c xcode automatic-ref-counting
    Possible Duplicate:iOS: to ARC or not to ARC? Pros and Cons i have learned about What are the advantages and disadvantages of using ARC?from What are the advantages and disadvantages of using ARC?However i still doubt in automatic reference counting (ARC).I have some queries here.We don’t want to do the release manually, if the ARC is active?is it do the automatic garbage collection and memory management automatically?Could any one please clarify my thoughts.

  • Ralphleon
    objective-c ios xcode automatic-ref-counting
    After reading:iphone: submit app with iOS 5 and XCode 4.2?I realize that using ARC and expecting to release an app to the app store with this technology might have been a bit short-sighted of me. What is the best course of action for me? Use Xcode 4 and redo the memory management Wait for Xcode 4.2 to be released Some other magical way that will solve all my issues and make my dreams come trueThanks for the advice.Update: Just in case anyone wandered on to this, it was while Xcode 4.2 was still

  • Jacky
    ios automatic-ref-counting
    I’m just wondering about self.view = nil in ARC. when set self.view = nil, self.view will be automatically released? When set self.view = nil, all the subviews will be automatically nil and released?Thanks

  • Avner Barr
    ios objective-c automatic-ref-counting objective-c-blocks retain-cycle
    From my understanding when an object method receives a block as a completion argument I can send “self” in the block:[object doMethodWithCompletion:^{[self doSomethingWhenThisMethodCompletes] }];but if this object “retains” the block (saves it for future use) I should send a “weak” copy of myself:__weak __typeof__(self) weakSelf = self; object.savedBlock = ^{[weakSelf doSomethingWhenThisBlockIsCalledFromWithinObject]; };but I have also seen variants such as:__weak __typeof__(self) weakSelf = sel

  • Brad Larson
    objective-c automatic-ref-counting selector
    I am doing an exercise to learn how to use selectors in Objective-C. In this code I am trying to compare two strings: int main (int argc, const char * argv[]) {@autoreleasepool{SEL selector= @selector(caseInsensitiveCompare:);NSString* str1=@”hello”;NSString* str2=@”hello”;id result=[str1 performSelector: selector withObject: str2];NSLog(@”%d”,[result boolValue]);}return 0; }But it prints zero.Why? Edit: And if I change str2 to @”hell” I get an EXC_BAD_ACCESS.

  • user2417281
    ios automatic-ref-counting
    I have a problem with an Objective-C class, when ARC is enabled.My classes looks like these:@interface ParentClass : NSObject { }-(void)decodeMethod; @end@implementation ParentClass-(void)decodeMethod{ }@end@interface ChilldClass : ParentClass{int *buffer; } @end@implementation ChildClass-(id)init{self = [super init];if(self != nil){buffer = (int *)malloc(20*sizeof(int));}return self; }-(void)dealloc{free(buffer); }@endI have another class like this one:@interface OtherClass : NSObject{ParentCla

  • Jim
    ios objective-c automatic-ref-counting sudzc
    Edit – I’ve tracked the below issue to a 64-bit vs 32-bit architecture issue… see my posted answer for how I resolvedI’ve used SudzC to generate SOAP code for a web service. They supply you with a sample application, which I was able to use successfully, both on device and simulator.I then started building out my app. I imported the SudzC generated files into a new XCode project using the blank application template (with CoreData and ARC enabled).I got the first SOAP request up and running —

  • hodgesmr
    ios objective-c automatic-ref-counting
    Let’s say I’m trying to access self from within a block:[someObject successBlock:^(NSArray *result) {[self someSuccessMethod]; } failure:^(NSString *errorMessage, int status) {[self someFailureMethod]; }];I understand that this creates a retain cycle and that someObject and self never get de-alloced.What’s confusing me is what actually happens with/without the __block keyword. I can fix the retain cycle by making a __weak reference to self:__weak MyClass* me = self; [someObject successBlock:^(NS

  • Qing
    ios objective-c nsarray automatic-ref-counting dealloc
    I am new in Objective-C, the referenced count make me confused 🙁 . In ARC mode under Xcode 5.0.2, when I create a NSArray init with the objects, the dealloc methon of the object is not invoked, Why? Should I remove the objects from the Array manually?But it’s a NSArray, how? here is my test code://——LCDRound.h file————- @interface LCDRound : NSObject – (void)paint; @end //——LCDRound.m—————— @implementation LCDRound – (void)paint {NSLog(@”I am Round”); } – (void)deal

  • tonklon
    ios objective-c automatic-ref-counting nsnotificationcenter
    I have a situation in which it can happen, that the last strong reference to an observer is removed while the observer processes an incoming notification.That leads to the observer being deallocated immediately. I would normally expect, that a currently running method can finish before an object is deallocated. And this is what happens during normal message dispatch.A simplified version of the code:TKLAppDelegate.h:#import <UIKit/UIKit.h> #import “TKLNotificationObserver.h”@interface TKLAp

Web site is in building