I'm starting to understand memory management better in objective-c, but there's something I don't understand. This is a property declaration:
@property (nonatomic, retain)UILabel *myLabel;
and this is its unseen synthesized setter (I think):
- (void)setMyLabel:(UILabel *)newValue {
if(myLabel != newValue) {
[myLabel relea...
How to release this variable with no EXC_BAB_ACCESS ?
//First line create memory leak
UIImage *ImageAvatar = [[UIImage alloc] initWithData:[myg.imageData copy]];
Moins1 = ImageAvatar;
//[ImageAvatar release]; if i release-> EXC_BAD_ACCESS
Moins1 is a menber of the interface is declared like this :
UIImage *Moins1;
...
@property (non...
I have an NSDictionary which contains (my custom) GTPerson objects. GTPerson has an NSMutableSet *parents attribute, on which I use @property and @synthesize.
Out of my NSDictionary, I want to filter all the GTPerson objects which don't have any parents, i.e. where the count of parents is 0.
I'm using the following code:
NSPredicate ...
If I have a class, how can I list all its instance variable names?
eg:
@interface MyClass : NSObject {
int myInt;
NSString* myString;
NSMutableArray* myArray;
}
I would like to get "myInt", "myString", and "myArray". Is there some way to perhaps get an array of names that I can iterate over?
I've tried searching the Obj...
Usually, a UISearchDisplayController, when activated, dims the tableView and focuses the searchBar. As soon as you enter text into the searchBar, it creates a searchResultsTableView that displays between the searchBar and the keyboard. The searchDisplayController's delegate gets called when this second UITableView is loaded/shown/hidden/...
I'm working on a fairly simple iPhone app to solve the quadratic equation, mostly because it's so easy-at least the concepts and math!
I've created an interface in Interface Builder that has a couple Labels, 3 text fields (varAfield, etc) and a Solve button. The 3 text fields which are set as UITextFieldDelegate have been set so that th...
I have an array that creates several different sound file names in a specific order. I have successfully created the array but I am not sure how to call the value I got from the array as the file URL or how I implement it into AudioServicesPlaySystemSoundID.
This is the code I have so far:
- (void)viewDidLoad {
NSArr...
I'm coming from Ruby to Objective-C and I keep doing:
NSObject *foo;
@property (nonatomic,retain) NSObject *foo;
in the .h file, and then in .m file:
@synthesize foo;
at the top and
[foo release]
in dealloc.
It's 4 steps to add foo! Do seasoned Objective-C programmers do all four steps manually each and every time they want t...
What reasons are there for doing in three lines what could be done in one?
Here is some code from developer.apple.com:
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;
[aNavigationController release];
.....
I want my application to never just crash stupidly. I know that code quality is the root solution for this. But I still need an application to never crash when some unexpected bug happens. Here is code I want to try.
-(void)testException
{
@try
{
NSString* str;
[str release];
}
@catch(NSException* ex)
...
Does @synchronized not use "lock" and "unlock" to achieve mutual exclusion? How does it do lock/unlock then?
The output of the following program is only "Hello World".
@interface MyLock: NSLock<NSLocking>
@end
@implementation MyLock
- (id)init {
return [super init];
}
- (void)lock {
NSLog(@"before lock");
[super lock];
...
I'm going to have a 10x10 grid of UIButton objects. Each of these UIButtons is going to need to be referenced by the row and column number, so they should probably be stored in some type of an array.
My question: what is the easiest way to create this grid? Programmatically or through the Interface Builder? If programmatically, what wou...
Hi,
I've just started learning Obj-C. As an alternative to the usual maths examples, I thought I'd try and create a countdown timer - perhaps one that could time multiple events.
Have looked at NSTimer but am having trouble working it out - especially which method to use.
I've tried to find some source code - but so far it's all Cocoa...
How can I use both of these in the same UIView correctly?
I have one custom subclassed CALayer in which I draw a pattern within drawInContext
I have a another in which I set an overlay PNG image as the contents.
I have a third which is just a background.
How do I overlay all 3 of these items?
[self.layer addSublayer:bottomLayer]; ...
Can I do any of the following? Will they properly lock/unlock the same object? Why or why not? Assume there are many identical threads using global variable "obj", which was initialized before all threads started.
1.
@synchronized(obj) {
[obj release];
obj = nil;
}
2.
@synchronized(obj) {
obj = [[NSObject new] autorelea...
First of all, i have never seen so many memory issues in my app since i started placing "self" everywhere after reading an article about how memory behaves in obj-C. Now, im getting all kinds of issues (reveals the sloppiness of my coding). Granted I am a newbie at Objective-C, i'll admit i have never had so much issues with memory manag...
In C#, if I wanted to parse out a string into a date and timespan, I'd do something similar to the following:
String input = "08:00";
DateTime time;
if (!DateTime.TryParse(input, out time))
{
// invalid input
return;
}
TimeSpan timeSpan = new TimeSpan(time.Hour, time.Minute, time.Second);
My Google-Fu has been less than desir...
I'm still getting my feet wet with the iPhone SDK, but I'm wondering if it would be possible to get the ConnectionKit framework working for an iPhone app. I know it was developed for the desktop OS, so I'm not sure what sort of dependencies it has and whether or not it could be shoehorned into the iPhone OS.
In my case, I would like to ...
I want to show some images as a thumbnail in View controller but i dont know how to do this. Can anyone please give me some ideas or sample code if possible.
...
I've implemented a bit of code from one of the many Apple code examples, but I'm having a bit of trouble, because the retain attribute of one of the properties doesn't appear to be working. Here's the property declaration:
@property (nonatomic, retain) EditingViewController *editingViewController;
And here's the code:
- (EditingViewC...