Downcasting Objective-C instance variables in subclasses

I have a class A with an instance variable of type X.@interface A : NSObject { X *x;}@endSome of the X instances additionally conform to a protocol P. I want to implement a specialized version of A specifically for those X instances.@interface B : A { X <P> *x;}@endThis compiles fine. However, when I access x from a B instance, the change is not propagated to A. Therefore, functions of A that are not redefined use an other X instance than the functions of B.Is it somehow possible to redefine an instance variable when only a protocol is added?There is a similar q...

Shift hue of an RGB Color

I'm trying to write a function to shift the hue of an RGB color. Specifically I'm using it in an iOS app, but the math is universal.The graph below shows how the R, G, and B values change with respect to the hue.Looking at that it seems like it should be a relatively simple to write a function to shift the hue without doing any nasty conversions to a different color format which would introduce more error (which could be an issue if continue applying small shifts to a color), and I suspect would be more computationally expensive.Here is what I have so far which sort of work...

compile object code in linux error (.text+0x20): undefined reference to `main'

im triying to compile a object from the source http://xeat-engine.googlecode.com/svn/trunk/using the codeg++ -c wx-config --cxxflags main.cppg++ -o main main.o wx-config --libsand obtain the error/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function _start':(.text+0x20): undefined reference tomain'collect2: error: ld returned 1 exit statusplease help me to fix the problemWhat could I do?IS A CAPTURE FOR MAIN.CPPhttp://i.stack.imgur.com/TziYb.jpg You're missing:wxIMPLEMENT_APP(xeatengine_guiApp);which will be expanded into a valid main() function...

addSubview from different file

In a game I am making, I made a class file called bomb. In the file, I have a method called displayBomb: - (void) displayBomb { bombImage = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)]; }The method is supposed to make an image display on the screen. In my ViewController.m file in ViewDidLoad, I have: bomb *bomb1 = [[bomb alloc] init]; [bomb1 setValue:[UIImage imageNamed:@"image.png"] forKey:@"bombImage"]; [bomb1 displayBomb];It doesn't display anything, though. I think the problem is that I need something like [self.view addSub...

How to uses already initialized class in another View?

I am making an iOS app with multiple tab views. Two of the views use the same view controller so therefore they both have an instance. I wanted to know if it was possible to use only one instance of the view controller for two views. The reason i want to do this is because i have a "Connect" and "Disconnect" button on one view that uses the GameKit peer picker and i have "Send File" on another view that has to use the session that i created from the other view with the connect button. In any viewController which belongs to the tabBarController:UIViewController *vc1 = [se...

Class variable values get lost

I've got a image class where I want to store some information according to an image:@interface GEOImage : UIImage{ NSString *title; NSString *imgDescription; NSString *latitude; NSString *longitude; NSDictionary *info; NSURL *urlToImage;}@property (nonatomic, retain) NSString *title, *imgDescription, *latitude, *longitude;@property (nonatomic, retain) NSDictionary *info;@property (nonatomic, retain) NSURL *urlToImage;@endIn a first tab of TabBarController I set for example:self.chosenImage.title = @"Roflmao"and in another second tab I print it out:NSLog("T...

Identifying the name of a class during run time

So I have run into a fairly complex problem with my application.I have about 40 UIImageView objects that need to be displayed at different locations when different ones are stacked (EX img 1 needs to take img 2 place if img2 ==NO).What I am trying to do is use a "for loop" and run through all my Boolean values that check if the image is selected.I was curious if it is at all possible to call variable like this-(IBAction) button:(id) sender{ scrollView.hidden = YES; NSInteger i = 1; (@"imagenumber%d", i) = [[UIImageView alloc] initWithFrame: CGRectMake (28, 230, 86,...

How to perform chmod() in Objective C

What's the equivalent of C's: chmod(MY_FILE, 0777);in Objective C? I am trying to write to an existing locked file without performing chmod +x MY_FILEon the terminal. You can use C's chmod().Enter man 2 chmod in the terminal for the documentation and related functions. [XXX]You can use Cocoa's -setAttributes:ofItemAtPath:error: to do this job.[[NSFileManager defaultManager] setAttributes:@{ NSFilePosixPermissions : @0666 } ofItemAtPath:… error:&error];Of course you need the rights to do that. ...

Objective C custom class methods not being called

So I have this custom class with just a test method that does nslog. I am going to reuse this method many times in my app. The interface looks like this.@interface TestViewController: UIViewController { CMImageMover * imageMover }Then in the view did load I:imageMover = [[CmImageMover alloc] init];If I do:[imageMover testMethod];Right after the alloc and init it works in the viewDidLoad function but if I call it again from another function in the view controller nothing works and the class method does not get called.What am I doing wrong here. Every other var I declare ...

obj-C/Cocoa passing parameters of unknown class (but common parentage) to method. Possible?

I have a collection of classes defined from UIView. @interface {UIView *thisViewUIView *thatView}...thisView *viewOne = [[thisView alloc] init];thatView *viewTwo = [[thatView alloc] init];Now, say I want to create a method that will take these objects and call a function that is common to them both and also set common parameters and do all kinds of unbeknownst things, how do I pass these objects on to it if they are of different classes (assuming they are quite dissimilar)?[self exampleMethod:viewOne];[self exampleMethod:viewTwo];- (void)exampleMethod:(UIView *)viewNumber /...

Sharing a variable between all instances of one class

Hey, I am making a imageloading system with my tablecells and I need each cell to share the same instance of my imageloader class. Sorry if this is a nooby question, but is it possible to archieve this? So what I am meaning is that if I have int variable in other instance of the same class, the value of the int variable is same in both classes.Thanks in advance! For a "single instance for everything", you need a singleton:+(SomeClass *)sharedInstance { static SomeClass *instance = nil; if (instance == nil) { instance = [[self alloc] init]; } return instance;}Then ...

Sending data between classes in Cocoa Objective C

I've started programming for iPhones about a month ago now, and have found the site very useful. So I though someone out there could help me.I think I understand the basics of how @property and @synthesise work and using setters and getters, but I have a problem.Say I have 3 classes: Functions, Class1 and Class2.Functions is a class that holds all the data and Class1 and Class2 reads that data from it and writes new data (amends the data) to it. However both Class1 and Class2 will make there own instance of Functions as it is basically just a blueprint for the data. So if C...

Extracting animated vertices from DAE/COLLADA using SceneKit

Using SceneKit on Mac OS X to load a COLLADA (DAE) file you can easily obtain all geometry by traversing the tree of SCNNode:s and their respective SCNGeometry:s, and extract the vertex data using [geometry geometrySourcesForSemantic: SCNGeometrySourceSemanticVertex].However, given a DAE file containing an animated object - is SceneKit capable of giving me the exact location of each vertex at a given time in the animation, or can I extract all the animation data from the associated CAAnimation objects?My use case is that I would like to use SceneKit to import DAE files, but...

Show conversations in Layer (with Atlas) even if there are no messages

I am trying to show all conversations that have been created, even if a message was not sent. However, I can't for the life of me figure it out. I've hit a million dead ends. Does anyone know if this is even possible?Perhaps a more specific question that would help me answer it is: is it possible to get an LYRConversation object of an existing conversation with just the user id of the other participant? After going through their docs for hours I finally found this: If you create a conversation the recipient won't see it until the first message is sent. If you want to...

How to play songs on Bluetooth-connected devices (app developed in Objective C)

I developed an iPhone application that works as a custom music player. I managed to get a list of all songs in my iPhone into a UITableView. When I play a song, sound comes out of the iPhone audio speakers instead of a Bluetooth-connected device.In this case, I connected an iPhone to Google Glass via Bluetooth. When a call is received on the iPhone, I can hear the caller through the Google Glass headset. When I play a song in my app, however, audio does not get redirected to the Glass headset. The audio plays through the iPhone's speakers. What I had intended was for the mu...

crash after clicking the button on a UIAlertview

i have method for showing Alertview in class named FAClass // FAClass.H#import <Foundation/Foundation.h>@interface FAClass : NSObject<NSURLConnectionDataDelegate>{}// FAClass.M@implementation FAClass{} - (void)ShowAlert{ UIAlertView *FACUpdateAlert = [[UIAlertView alloc]initWithTitle:Nil message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [FACUpdateAlert show];}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"%i",buttonIndex);}when try to call this method in anoth...

Page 1 of 250  |  Show More Pages:  Top Prev Next Last