Search Results

Search found 3457 results on 139 pages for 'cocoa'.

Page 17/139 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • iPhone noob - setting NSMutableDictionary entry inside Singleton?

    - by codemonkey
    Yet another iPhone/Objective-C noob question. I'm using a singleton to store app state information. I'm including the singleton in a Utilities class that holds it (and eventually other stuff). This utilities class is in turn included and used from various view controllers, etc. The utilities class is set up like this: // Utilities.h #import <Foundation/Foundation.h> @interface Utilities : NSObject { } + (id)GetAppState; - (id)GetAppDelegate; @end // Utilities.m #import "Utilities.h" #import "CHAPPAppDelegate.h" #import "AppState.h" @implementation Utilities CHAPPAppDelegate* GetAppDelegate() { return (CHAPPAppDelegate *)[UIApplication sharedApplication].delegate; } AppState* GetAppState() { return [GetAppDelegate() appState]; } @end ... and the AppState singleton looks like this: // AppState.h #import <Foundation/Foundation.h> @interface AppState : NSObject { NSMutableDictionary *challenge; NSString *challengeID; } @property (nonatomic, retain) NSMutableDictionary *challenge; @property (nonatomic, retain) NSString *challengeID; + (id)appState; @end // AppState.m #import "AppState.h" static AppState *neoAppState = nil; @implementation AppState @synthesize challengeID; @synthesize challenge; # pragma mark Singleton methods + (id)appState { @synchronized(self) { if (neoAppState == nil) [[self alloc] init]; } return neoAppState; } + (id)allocWithZone:(NSZone *)zone { @synchronized(self) { if (neoAppState == nil) { neoAppState = [super allocWithZone:zone]; return neoAppState; } } return nil; } - (id)copyWithZone:(NSZone *)zone { return self; } - (id)retain { return self; } - (unsigned)retainCount { return UINT_MAX; //denotes an object that cannot be released } - (void)release { // never release } - (id)init { if (self = [super init]) { challengeID = [[NSString alloc] initWithString:@"0"]; challenge = [NSMutableDictionary dictionary]; } return self; } - (void)dealloc { // should never be called, but just here for clarity [super dealloc]; } @end ... then, from a view controller I'm able to set the singleton's "challengeID" property like this: [GetAppState() setValue:@"wassup" forKey:@"challengeID"]; ... but when I try to set one of the "challenge" dictionary entry values like this: [[GetAppState() challenge] setObject:@"wassup" forKey:@"wassup"]; ... it fails giving me an "unrecognized selector sent..." error. I'm probably doing something really obviously dumb? Any insights/suggestions will be appreciated.

    Read the article

  • Can't compile code when working with CALayer

    - by Sheehan Alam
    For some reason I get linker errors when I try and use CALayer: "_OBJC_CLASS_$_CALayer", referenced from: I have imported the following headers: #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> Code: arrowImage = [[CALayer alloc] init];

    Read the article

  • Producer Consumer Issue with Core Data

    - by Mugunth Kumar
    I've a Core Data application. In the producer thread, I pull data from a web service and store it in my object and call save. My consumer object is a table view controller that displays the same. However, the app crashes and I get NSFetchedResultsController Error: expected to find object (entity: FeedEntry; id: 0xf46f40 ; data: ) in section (null) for deletion on the console. When I debug it, everything works fine. So I understood that it's like a race issue. How is these kind of problem solved? What's the best way to design a producer-consumer app with core-data?

    Read the article

  • How do I share an NSArrayController between two nib files?

    - by Tom Dalling
    I have an array of images, and two nib files. One nib file has a window that displays the images in an NSTableView. The other nib has a window that draws the array of images into an NSView, and also draws a highlight over the images that are selected. The array of images is controlled by an NSArrayController. I'm having trouble getting the two nibs to share the NSArrayController. I would have two separate NSArrayControllers bound to the same content, but I also want both nibs to share the controller's selection; that is, if you select an image in the table window, it also becomes selected in the other window. Is there a standard way to do this?

    Read the article

  • Finding text's bounding rect in Core Text

    - by Mo
    I'm trying to find the boundaries of a line of text in Core Text. For simplicity, assume it has a single character. At the moment I'm using the following method: line = CTLineCreateWithAttributedString(attrString); rect = CTLineGetImageBounds(line, context); It works most of the times, but for some characters, like math italic d (Unicode: 0x1D451) or math italic q (Unicode: 0x1D45E), the width is a bit short. I tried using CTLineGetTypographicBounds() or CTFramesetterSuggestFrameSizeWithConstraints, but they didn't help either (I think they use glyph's advance to find the width, not its graphical width.) As the font itself isn't italic, I also can't use slant angle to correct this. I tried accessing the glyphs directly and using CTFontCreatePathForGlyph(), but failed as CGGlyph and UniChar are both 16-bits and I need 32-bit characters. Does anyone know if I'm doing anything wrong? If so, what's the right way?

    Read the article

  • Generate vCard from AddressBook.framework

    - by Oliver
    I'm utilising the AddressBook.framework in my iPhone app, and I'd like to replicate something along the lines of the share feature in Contacts.app. This basically attach's a specific contacts vCard to an email. As far as I know, there is nothing in the documentation that mentions generating a vCard. Is this a case of generating one myself? Or is there something available that can help me?

    Read the article

  • Releasing NSData causes exception...

    - by badmanj
    Hi, Can someone please explain why the following code causes my app to bomb? NSData *myImage = UIImagePNGRepresentation(imageView.image); : [myImage release]; If I comment out the 'release' line, the app runs... but a few times calling the function containing this code and I get a crash - I guess caused by a memory leak. Even if I comment EVERYTHING else in the function out and just leave those two lines, when the release executes, the app crashes. I'm sure this must be a newbie "you don't know how to clean up your mess properly" kind of thing ;-) Cheers, Jamie.

    Read the article

  • plist vs static array

    - by morticae
    Generally, I use static arrays and dictionaries for containing lookup tables in my classes. However, with the number of classes creeping quickly into the hundreds, I'm hesitant to continue using this pattern. Even if these static collections are initialized lazily, I've essentially got a bounded memory leak going on as someone uses my app. Most of these are arrays of strings so I can convert strings into NSInteger constants that can be used with switch statements, etc. I could just recreate the array/dictionary on every call, but many of these functions are used heavily and/or in tight loops. So I'm trying to come up with a pattern that is both performant and not persistent. If I store the information in a plist, does the iphoneOS do anything intelligent about caching those when loaded? Do you have another method that might be related?

    Read the article

  • Two UITabBarControllers and Autorotation

    - by optimisticmonkey
    I have two UITabBarControllers in my mainwnidow.nib wired to my appdelegate. In my app delegate, I can load either one: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //either [window addSubview:tabBarController.view]; //or [window addSubview:tabBar2Controller.view]; [window makeKeyAndVisible]; } and autorotation works. If I add both (with the expectation to swap between them later): [window addSubview:tabBarController.view]; [window addSubview:tabBar2Controller.view]; then autorotation stops working...everything is always portrait. Thanks in advance for any tips...

    Read the article

  • How to allow one thread to mutate an array property while another thread iterates on a copy of the a

    - by Steve918
    I would like to implement an observer pattern in Objective-C where the observer implements an interface similar to SKPaymentTransactionObserver and the observable class just extends my base observable. My observable class looks something like what is below. Notice I'm making copies of the observers before enumeration to avoid throwing an exception . I've tried adding an NSLock around add observers and notify observers, but I run into a deadlock. What would be the proper way to handle concurrency when observers are being added as notifications are being sent? @implementation Observable -(void)notifyObservers:(SEL)selector { @synchronized(self) { NSSet* observer_copy = [observers copy]; for (id observer in observer_copy) { if([observer respondsToSelector: selector]) { [observer performSelector: selector]; } } [observer_copy release]; } } -(void)notifyObservers:(SEL)selector withObject:(id)arg1 withObject:(id)arg2 { @synchronized(self) { NSSet* observer_copy = [observers copy]; for (id observer in observer_copy) { if([observer respondsToSelector: selector]) { [observer performSelector: selector withObject: arg1 withObject: arg2]; } } [observer_copy release]; } } -(void)addObserver:(id)observer { @synchronized(self) { [observers addObject: observer]; } } -(void)removeObserver:(id)observer { @synchronized(self) { [observers removeObject: observer]; } }

    Read the article

  • NSNumberFormatter customize?

    - by Frederick C. Lee
    I wish to use NSNumberFormatter to merely attached a percent ('%') to the supplied number WITHOUT having it multiplied by 100. The canned kCFNumberFormatterPercentStyle automatically x100 which I don't want. For example, converting 5.0 to 5.0% versus 500%. Using the following: NSNumberFormatter *percentFormatter = [[NSNumberFormatter alloc] init]; [percentFormatter setNumberFormat:@"##0.00%;-##0.00%"]; But 'setNumberFormat' doesn't exist in NSNumberFomatter. I need to use this NSNumberFormatter for my Core-Plot label. How can I customize NSNumberFormat? Ric.

    Read the article

  • What's the standard convention for creating a new NSArray from an existing NSArray?

    - by Prairiedogg
    Let's say I have an NSArray of NSDictionaries that is 10 elements long. I want to create a second NSArray with the values for a single key on each dictionary. The best way I can figure to do this is: NSMutableArray *nameArray = [[NSMutableArray alloc] initWithCapacity:[array count]]; for (NSDictionary *p in array) { [nameArray addObject:[p objectForKey:@"name"]]; } self.my_new_array = array; [array release]; [nameArray release]; } But in theory, I should be able to get away with not using a mutable array and using a counter in conjunction with [nameArray addObjectAtIndex:count], because the new list should be exactly as long as the old list. Please note that I am NOT trying to filter for a subset of the original array, but make a new array with exactly the same number of elements, just with values dredged up from the some arbitrary attribute of each element in the array. In python one could solve this problem like this: new_list = [p['name'] for p in old_list] or if you were a masochist, like this: new_list = map(lambda p: p['name'], old_list) Having to be slightly more explicit in objective-c makes me wonder if there is an accepted common way of handling these situations.

    Read the article

  • Call method with parameters after animation completion

    - by Jean
    I want to call a method with certain parameters once an animation is done. The flow is something like this: -(void) myMethod:(int)val { [self performAnimation]; [self doSomethingElse:val]; // This should be done after animation completion } I presume the 'doSomethingElse' method needs to be called from the method defined in 'setAnimationDidStopSelector' - or is there a way to have the animation block until done? What is the best way to let the method called on 'setAnimationDidStopSelector' know about the method it needs to call and its parameter? Can this be done with selectors? Or is the only way of doing this by storing the methods and its params in class temp variables and access them when needed?

    Read the article

  • Accessing Web Service from iPhone

    - by Cody C
    Questions on calling web services from iPhone? Anyone have any recommended tutorials on doing this? Anyone have any best practices on implementing security with these calls? Has anyone made or seen any shared libraries or wrappers for easy web service calls from the iPhone?

    Read the article

  • Subclassing UIButton but can't access my properties

    - by Ross Ellerington
    Hi, I've created a sub class of UIButton: // // DetailButton.h #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface MyDetailButton : UIButton { NSObject *annotation; } @property (nonatomic, retain) NSObject *annotation; @end // // DetailButton.m // #import "MyDetailButton.h" @implementation MyDetailButton @synthesize annotation; @end I figured that I can then create this object and set the annotation object by doing the following: MyDetailButton* rightButton = [MyDetailButton buttonWithType:UIButtonTypeDetailDisclosure]; rightButton.annotation = localAnnotation; localAnnotation is an NSObject but it is really an MKAnnotation. I can't see why this doesn't work but at runtime I get this error: 2010-05-27 10:37:29.214 DonorMapProto1[5241:207] *** -[UIButton annotation]: unrecognized selector sent to instance 0x445a190 2010-05-27 10:37:29.215 DonorMapProto1[5241:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIButton annotation]: unrecognized selector sent to instance 0x445a190' ' I can't see why it's even looking at UIButton because I've subclassed that so it should be looking at the MyDetailButton class to set that annotation property. Have I missed something really obvious. It feels like it :) Thanks in advance for any help you can provide Ross

    Read the article

  • How do I bind an iTunes style source list to an NSTableView using Core Data?

    - by Austin
    I have an iTunes style interface in my application: Source list (NSOutlineView) on the left that contains different libraries and playlists with an NSTableView on the right side of the interface displaying information for "Presentations". Similar to iTunes, I am showing the same type of information in the table view whether a library or playlist is selected (title, author, date created, etc). I currently have an NSArrayController connected to my NSTableView and was setting the fetch predicate based on what was selected in the source list. This works fine when selecting a library because I can just set the fetch predicate to filter by the "type" field in my Presentation Core Data entity. When I try to adjust the fetch predicate for the playlist however, it doesn't look like there is any way to set the fetch predicate because I've got a table in between Playlists and Presentations to keep up with the order within the Playlist. According to the Apple docs, these type of predicates are not doable with Core Data (it basically doesn't multiple inner joins). Below is the relevant portion of my Data Model. Is my data model setup incorrectly? Should I drop the NSArrayController and handle connecting the NSTableView up by hand? I'm trying to figure out if there is a simple fix, or really a design flaw.

    Read the article

  • Choose build configuration for referenced subproject

    - by Jaka Jancar
    I have an iPhone project which references a framework as a subproject. The framework has the following configurations: Debug Release My app has the following configurations: Debug Release Distribution-AdHoc Distribution-AppStore I would like the framework to be built with different configurations, depending on the app configuration: Debug - Debug Release - Release Distribution-AdHoc - Release Distribution-AppStore - Release How can I achieve this?

    Read the article

  • MKAnnotationView for userLocation pin iPhone

    - by Mauricio Galindo
    I have an application that uses MKMapView and at some point in the app I need to remove all the current pins in the map using [mapView removeAnnotations:mapView.annotations] And then I want to show again the current user location mapView.showUserLocation = YES But I can only make it reappear as a regular pin, because the userLocation view class its not public so I cant return views of that type. Here is my code - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation MKPinAnnotationView* annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"currentloc"]; if (!annView) { MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; annView.pinColor = MKPinAnnotationColorRed; annView.animatesDrop=TRUE; annView.canShowCallout = YES; annView.calloutOffset = CGPointMake(-5, 5); if ([annotation isKindOfClass:[DraggableAnnotationAM class]] ) annView.draggable = YES; return annView; } else { if ([annotation isKindOfClass:[DraggableAnnotationAM class]] ) annView.draggable = YES; annView.annotation = annotation; return annView; } Also I have found through reflection that MKUserLocationView is the class that is used to display the current location, but because its not public its not safe to use and my app keeps crashing and Im sure theres a easier way. Is it possible to do what I want, or should I just never remove the user location annotation of the mapView? Thanks in advance

    Read the article

  • How do I return the entire set / array using NSPredicate?

    - by Prairiedogg
    I'm building a carArray and want to filter the contents conditionally, using an NSPredicate, like so: NSPredicate *pred; switch (carType) { case FreeCar: pred = [NSPredicate predicateWithFormat:@"premium = NO"]; break; case PremiumCar: pred = [NSPredicate predicateWithFormat:@"premium = YES"]; break; default: pred = [NSPredicate predicateWithFormat:@"SOME PREDICATE THAT RETURNS EVERYTHING"]; break; } self.carArray = [aCarArrayIGotFromSomewhere filteredArrayUsingPredicate:pred]; My question is, what is the correct syntax for the value I've stubbed in as SOME PREDICATE THAT RETURNS EVERYTHING which returns all of the instances in the array / set? PS - I know the answer and will post it immediately, just sharing it for everyone's reference as an earlier search on SO did not yield the result.

    Read the article

  • NSOperation for animation loop causes strange scrolling behaviour

    - by Tricky
    Hi, I've created an animation loop which I run as an operation in order to keep the rest of my interface responsive. Whilst almost there, there is still one remaining issue. My UIScrollViews don't seem to be reliably picking up when a user touch ends. What this means is, for example, if a user drags down on a scroll view, when they lift their fingers the scrollview doesn't bounce back into place and the scrollbar remains visible. As if the finger hasn't left the screen. It takes another tap on the scrollview for it to snap to its correct position and the scrollbar to fade away... Here's the loop I created in a subclassed NSOperation: (void)main { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; _displayLink = [[CADisplayLink displayLinkWithTarget: self selector: @selector(animationLoop:)] retain]; [_displayLink setFrameInterval: 1.0f]; [_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode: NSRunLoopCommonModes]; while (![self isCancelled]) { NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init]; [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; [loopPool drain]; } [_displayLink invalidate]; [pool release]; } DOes anyone have any idea what might be going on here, and even better how to fix it... Thanks!

    Read the article

  • Background problem on UITableView

    - by f0rz
    Hi ! I have come to a problem, wich I have no idea how to solve. Can anyone think outside the box and point me to right directions? I would be very thankfull ! The problem. I have a UITableView containing a first row wich is always the same (a empty row with repeating background) Next rows are bounch of dynamic data rows. I have set the yellow background on my UITableView in IBuilder, My cells (except first row) have white background with code: UIView* backgroundView = [ [ [ UIView alloc ] initWithFrame:CGRectZero ] autorelease ]; backgroundView.backgroundColor = [UIColor colorWithRed: 0.96078431372549 green: 0.96078431372549 blue: 0.96078431372549 alpha: 1.0]; cell.backgroundView = backgroundView; for ( UIView* view in cell.contentView.subviews ) { view.backgroundColor = [ UIColor clearColor ]; } The example yellow background, I only want to be showed at the top. As u see img example below. The thing is I dont want to have yellow background under the last datarow, I want to contain same white color I have on the cells. This should be white as the cells. Not yellow. Thank u for your time. Regards

    Read the article

  • Threading questions

    - by JK
    If I spawn a secondary thread and the threaded method calls other methods, are those methods run in the secondary thread or the main thread? Is there a way to determine on which thread a specified piece of code is being run?

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >