Skip to main content

Posts

create an Object and NIL value

I am used to have this in my code myClass.h @property ( strong, nonatomic ) ClassA *varA myClass.m varA = [[ClassA alloc] init]; if ( varA isEqual:nil ) NSLog@"var A is nil"); else NSLog@"var A is not nil"); this is a result from console var A is not nil I thought var A should be nil then. So my question is what does blue line do and why var A is not nil after all

Cocos2D iPhone - will this save memory?

When you create a sprite on cocos using a texture you allocate memory. Something like: CCTexture2D *textureProxy = [[CCTexture2D alloc] initWithImage:image]; CCSprite *proxy1 = [CCSprite spriteWithTexture:textureProxy]; My question is: suppose I want several sprites using the same texture and I do CCSprite *proxy1 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy2 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy3 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy4 = [CCSprite spriteWithTexture:textureProxy]; CCSprite *proxy5 = [CCSprite spriteWithTexture:textureProxy]; Will I use 5 times more memory? (or in other words, will the texture be duplicated to each proxy or is the sprite just a "empty box" that references the original texture? If the later is the answer, then the memory usage for similar sprites are not that huge, right? thanks.

Iphone Push Notification Wrong Device Token

Finally,I found out the sandbox tokens,which were mixed with the production tokens,and I update the code,receive the error response from apple,when post a sandbox token to apple,the next tokens all failed....While the push msg was "$payload['aps'] = array('content-available' => 1); ",apple will push the msg ,but the device will not show this msg,when I find the wrong one,I delete it,and retest. There is an amusing problem of apple push notification service: when I generate a post notification for my device and send to apple's server,for a while,my device will receive the notification. But if I first post a notification by a wrong devicetoken,then post a right notification to my device,my device will be responseless,just like the push notification was eaten by apple? What wrong with this? I use php code for push service,here is the most important part: $payload['aps'] = array('content-available' => 1); while ($line = mysql_fetc

Create a persistent store for Core Data

I did the tutorial on apples site, the Core Data tutorial for iOS and i did this tutorial about 3 times to see if i was mistaken, But when i finish the tutorial, it says that the app should work and be able to add Events to the table view, but when i press the + button, the app crashes and the console says: Cannot do save operation. There is no persistent store How could i fix this? I checked my code and i have everything!! Thanks in advance!

""CCLayer" may not respond to … ”

Playing with cocos2d and this seems to come up in some instances of message passing. I have to admit, I'm not well versed in Objective-C yet as I'm reading through the book as I write some code. For people familiar with cocos2d, you have a CCLayer class. In my case, I have a GameLayer which has some children layers, like so: @interface GameLayer : CCLayer { CCSprite *_background; CCPanZoomController *_controller; CCLayer *_truckLayer; } I then have a special initWithLayers method to add my child layers within this layer: -(id)initWithLayers:(TruckLayer *)truck { if( (self=[super init])) { self.truckLayer = truck; ..... } Now if I ever send a message to self.truckLayer I get the following warning in Xcode: 'CCLayer' may not respond to 'getNextAvailableSpot' An example might be doing something like so: CGPoint nextSpot = [self.truckLayer getNextAvailbleSpot]; All this code compiles and runs successfully, so I'm curious as to w

how to add some space in uiwebview [closed]

Now I have an uiwebview ,but I need some space right and left of the text.and I just write code programmatically,don't use IB. m_webView = [[UIWebView alloc] initWithFrame:CGRectMake(11, 95, 298, 350)]; NSString * path = [[NSBundle mainBundle] bundlePath]; NSURL * baseURL = [NSURL fileURLWithPath:path]; NSString * htmlString = [NSString stringWithFormat:defString, NSLocalizedString(@"kTerms_and_Legal_content_text", nil)]; [m_webView loadHTMLString:htmlString baseURL:baseURL];

unarchiveObjectWithFile returns NSArray

I am working on NSKeyArchive and running into the problem... What I am having so far is 1.-(BOOL)archiveItem 2.{ 3. NSString *path = [self findPath]; 4. if ([NSKeyedArchiver archiveRootObject:items toFile:wishListPath]) 5. { 6. return YES; 7. }else{ 8. return NO; 9. } 10.} 11.-(BOOL)unarchiveItem 12.{ 13. NSString *path = [self findPath]; 14. self.items = [NSKeyedUnarchiver unarchiveObjectWithFile:path]; 15. NSLog(@"Class of items is %@",[self.items class]); 16. if (self.items == nil) 17. return NO; 18. else 19. return YES; 20.} In my header file, items is declared like @property (nonatomic, copy) NSMutableArray *items; However, line 15 shows that type of items is NSArray ( not NSMutablArray) Does anyone have an idea about this one,please help. All comments are welcomed. Thanks