IPhone Development - returning an instance

With code like,
NSString *str;
int x = 3
str = [NSString stringWithFormat:@"%i", x];
How would I go about coding something like that for my own class, where I return an instance? Right now I'm doing this:
Fraction *f = [[Fraction alloc] initWithNumerator:3 andDenominator:5];
[f autorelease];
return f;
and I'd like to do:
return [Fraction fractionWithNumerator:3 andDenominator:5];
Thanks

If I'm understanding your question correctly, you want a class method that will return an autoreleased instance of a Fraction*.
So, change your method from:
- (Fraction *)initWithNumerator:(int)n andDenominator:(int)d;
to something like:
+ (Fraction *)fractionWithNumerator:(int)n andDenominator:(int)d;
and change your:
- (Fraction *)initWithNumerator:(int)n andDenominator:(int)d {
[super init];
if (self) {
[self setNumerator:n andDenominator:d];
return self;
to something like:
+ (Fraction *)fractionWithNumerator:(int)n andDenominator:(int)d {
Fraction* f;
f = [[self alloc] init]);
[f setNumerator:n andDenominator:d];
return [f autorelease];

Similar Messages

  • DotNet developer trying to make sence of iPhone development tools..

    Is there any useful links or tutorials for a newbie iphone developer from DotNet world ?
    I have been trying for the past one week to set a title to a tableView that i drag n dropped thru the interface builder. I learned the connection procedure and i was able to show the text cell 1 and cell 2 using the following code.
    #pragma mark -
    #pragma mark <UITableViewDataSource> methods
    -(UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"MyCell";
    UITableViewCell *cell = [self.tblView dequeueReusableCellWithIdentifier:identifier];
    if(cell == nil)
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier] autorelease];
    cell.text = [[NSString alloc] initWithFormat:@"Cell : %i", indexPath.row];
    return cell;
    -(NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section {
    //Every cell is going to have two rows.
    return 2;
    How to chage the title, group header or whatever they call it... It shows CALIFORNIA when a new treeView control is created in Interface builder...
    Pls help

    Thank you for the reply..
    I have added the following code and managed to display an (ugly) white label with the text on top of the list. Hurrey !
    - (UIView *)tableView:(UITableView *)tblView viewForHeaderInSection:(NSInteger)section {
    UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,0,0)];
    lbl.text = @"title";
    return lbl;
    But it doesn't look any similar to the title CALIFORNIA displayed in blue color without the BG rectangle and all when the tableView style is set to GROUPED
    May be I can change the background color of the label to trasparent, set the foreground color , change the font style and position the text to make it look like the way CALIFORNIA is displayed... But is this the right way to do it ?
    Or is there any other way with which I can set the
    " tableViewGroupHeader.text = @"title"; " ???
    Any idea ?

  • IPhone Development - Switching Views

    First, let me mention that this post may be in the wrong forum, so if that is the case, please let me know to repost.
    Next, my question is very simple. I have two views. The first has a button. The second has some text. I want to switch from the first, which loads when the app starts, to the second. This should be pathetically easy, but I have yet to figure out how it's done. At this point, their must be a fundamental problem with the way that I am thinking about how Windows and Views are managed, because based on my current beliefs, I cannot figure the rest out. I have created several "1-View" applications and, for what I am trying to do, have created several Views each of which do what I want them to do. But, I cannot find a way to switch from one to the other. I go to several homemade videos of people doing it, but no two people do it the same way and they all have their own little tricks to getting it done. This leads me to believe that it's not simply a matter of a lack of documentation by Apple, but that Apple doesn't even have a standard. Instead the have several hacked-together solutions that each can kind-of work depending on the situation.
    Here is the way I am conceptualizing it and maybe someone can show me the error in my thinking. I create a View-based application for the iPhone. I believe that the AppDelegate class that is created for me appears to really just be a Window/View manager class in that it keeps track of the one and only Window and manages which View is currently being displayed in that Window. Then, there is the MainWindow.xib file which is really confusing, because it simply populates itself with whatever is in the ViewController.xib file. It's never even mentioned in any of the code I am given. I imagine it is mentioned elsewhere, but that is irrelevant.
    Now, the ViewController.xib file is used along with Interface Builder to create a View from Widgets and link those Widgets' references and corresponding actions to class variables and methods in its corresponding ViewController.h and ViewController.m files. So, it would follow then, that if I wanted to create a second View, so that when a button on the first view was clicked a new, second View would be shown, I would create a new "View.xib" file and corresponding .h and .m files for it. Then, I have a method in my AppDelegate that takes a UIView object and removes whatever view is currently the subview of the window and adds the parameterized view as the new subview. This is also where I would put my transitions.
    Now, the new View that I just created doesn't contain the Title Bar or whatever it's called where the battery monitor icon, carrier icon, etc. exist, so this means that whenever I am actually putting Widgets in the View I have to just remember to avoid it and that the "auto-alignment" thing is off. So, I try other options, and create a new "Window XIB". This blows my freakin' mind, because it appears to be what I want despite it being called a Window and not a View. So, I try the "Write Class File", and it creates a new class called UIWindow which is a subclass of UIView. But wait, aren't Views supposed to be what populates the Windows, and UIWindow is a class that already exists. AHHH!!!!
    So, I rename the class to SecondView and create an instance of it in the AppDelegate. Now, I go into the AppDelegate.m file and change "window addSubview:viewController.view" to "window addSubview:secondView.view" (Edit: Brackets aren't allowed, so I am using quotes in their place here.) which doesn't compile, because it is a subtype of UIView which doesn't have a view member variable, only UIViewController does. So, I change it to make it a subclass of UIViewController which has a view member variable, and it compiles and shows a blank white screen of which neither of my views look like. Then, I go shoot myself in the face. It would appear that I need to link the new SecondView class to the SecondView.xib file somehow.
    It appears that the AppDelegate class should manage nothing and should only have a single UIWindow object that it loads. Then, the View Controller which has a View object should really have an array of all Views and should populate its view object with the currently needed View. This would make sense except that of all the How-tos I have seen none of them do it this way. I am sure that I didn't say everything that I need to say, but at this point I am so infuriated that I cannot think straight.
    <rant>
    I have developed in several different environments, and I have never come across such a simple and common concept implemented in such a convoluted way. Maybe I am simply missing something obvious, here, but if that's the case, Apple please please please make the documentation far less cryptic. I feel like I'm walking blindly through a jungle when I try to read the How-to documentation on your site. If I need to know some information about some class then it is relatively easy to get to, but trying to figure out how to actually do something within iPhone development is painful.
    I began trying to develop for the iPhone by just diving in and seeing what happened. That sort of failed, so I began reading your online help documentation and believe I took a step backwards. Finally, I bought a book on Objective-C that concluded with creating an iPhone app. I read it in a few days and now feel that I am rather proficient with the language as well as creating applications on the iPhone as long as they only consist of a single View in the ViewController class. All I want to do is switch from one View to another, and it shouldn't be this hard.
    </rant>
    Message was edited by: PhoenixRebourne

    Well odds are you won't find what you are looking for here unless another developer happens to come here. These forums all withing the support area are user to user forums to help with issues of usage, repairs, etc.
    Doesn't the developer area where you signed up to be a developer have forums?

  • IPhone developer page..

    I keep trying to apply to the iPhone developer program... and every time I log in with my apple ID, it says:
    "We apologize.
    We are experiencing technical difficulties. Please try again later.
    Please return to the iPhone Dev Center and try again."
    Anyone else getting this error? Is their site not working properly or what...

    Copied from this link.
    http://developer.apple.com/iphone/program/apply.html
    +*Standard Program $99*+
    +For developers who are creating free and commercial applications for iPhone and iPod touch and want to distribute applications on the App Store.+
    +*Enterprise Program $299*+
    +For companies with 500 or more employees who are creating proprietary in-house applications for iPhone and iPod touch.+
    Unless you just want to experiment, the SDK won't do you much good unless you plan on developing an app to be distributed via the iTunes app store, and you can't do that unless you pay for the Standard Program.

  • IPhone Development / Mobile Provision certificate

    Hi I'm trying to set up my ipod touch to start testing my apps on it. I'm following the instructions from the portal but when i load the provisioning certificate into the organizer I get the " A Valid Signing Identity Matching This Profile Could Not Be Found On Your Keychain" alert.
    Why does this alert occur and how do I rectify it.
    Thanks

    Hi New Developer, and welcome to the Dev Forum!
    Your Development Certificate and/or Private Key may not be installed correctly. As a first step I would recommend returning to the Portal and reviewing the instructions under Certificates->How To.
    Check under Certificates->Development to see if you have a valid Certificate. Also check your keychain by opening the Keychain Access app (in the Applications->Utilities folder). Select "login" from the upper-left Keychains panel, and "Certificates" from the lower-left Category panel. Make sure something like "iPhone Developer: your name" is listed in the right-center table. You should also find a listing for an "Apple Worldwide Developer Relations" certificate. Next select "Keys" from the Category panel and see if a private key is listed with the same name found in your certificate.
    If you don't find one or more of the above items, repeat all of the How To instructions.
    Hope that helps!
    \- Ray

  • Returning multiple instances of the same object?

    I have a fairly straight forward swing test class that contains a combobox. The problem is that an object is not selected in the combobox because I get different objects when building the list and when setting the selected item.
    To test this, I've added the following set of 4 lines on three locations in the code:
    - immediately after Toplink is initialized
    - when setting the selected item
    - when the main exits (and the JFrame is open)
    Stand s = Stand.findByPK(4).getDerrivedfromstand();
    System.out.println( s + ", Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
    s = Stand.findByPK(1);
    System.out.println( s + ", Using EM #" + Integer.toHexString( lEntityManager.hashCode() ) );
    I happen to know that Stand 4 is derrived from Stand 1. So I get Stand 1 once via Stand 4 and once directly. The result is:
    java.vm.version=1.6.0-b105
    [TopLink Info]: 2007.05.30 11:01:10.531--ServerSession(33414193)--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))
    [TopLink Info]: 2007.05.30 11:01:11.343--ServerSession(33414193)--file:/C:/Documents%20and%20Settings/toeu/My%20Documents/kp/reinders/reinders/voorraad/container/bm/build/-reinders login successful
    // immediatly after Toplink init
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@1866417, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@1866417, Standnr=1, Using EM #1a8e53c
    // when filling a combobox in the GUI
    executeQuery: SELECT ... FROM stand ORDER BY standid ASC
    getElementAt 0 = nl.reinders.bm.Stand@1866417, Standnr=1
    // when setting the value of the combobox
    executeQuery: SELECT ... FROM stand ORDER BY standid ASC
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    // when exiting the main (JFrame is open)
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=4 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    [1] setObject=1 / SELECT ... FROM stand WHERE (standnr = >>>HERE<<< )
    executeQuery: SELECT ... FROM stand WHERE (standnr = ?)
    nl.reinders.bm.Stand@171ef98, Standnr=1, Using EM #1a8e53c
    What is amazing is that somewhere after the combobox is filled, the query returns another instance of the same record and thus the select item will not find an "equal" object in the list. Any suggestions?

    Nevermind. A clear was done on the EM somewhere down the line.

  • Error when activating my iPhone Developer Program membership

    Ive just paid 99 dollars for my iphone developer program, and recieved an email containing the activation code. As you probably know, youre supposed to click on this activation-code and it links you to another site. But instead of activation I recieve this error-message on this site:
    "We are unable to activate your iPhone Developer Program membership because we are unable to successfully verify your identity. Please contact us and reference Enrollment ID# XXXXXXXXXX for further assistance."
    There was no problem verifying my identity when I paid for it. How come thats an issue now?
    Since people seem to have to wait for enormous periods of time to get even the simplest questions answered by Apple regarding the Dev Program, I thought I post this here to see if someone else have come across this, and what to do about it (except for waiting indefinitely).

    Mine got activated after a few days with no need for further information from me so if you get that same message you probably don't need to worry.

  • Hi, I upgraded my iphone 4 to iso 5 beta 6, but now it shows "No Service" at top left, and unable to complete your activation. Also tels that this device is not registered as part of the iphone developer programme. How could I fix this problem? Please..?

    Hi, I upgraded my iphone 4 (4.3.3) to iso 5 beta 6, but now it shows "No Service" at top left, and unable to complete your activation. Also tells that "this device is not registered as part of the iphone developer programme." How could I fix this problem? Please help me...,

    I had a similar occurrence with my just activated iPhone 4.
    I had been using the phone for three days when an odd occurrence with voice mail caused me to call tech support. After some discussion they decided to push the activation to my phone (even though I had been using it for three days). When I went to power it back up again I repeatedly got the "no service" notification. I got tech support on a land line and we tried hard reboots and so on. No joy. They told me to take it in to the point of sale and either the SIM card or the phone needed (or both) needed replacing.
    I tried one last hard reboot after dinner and the phone came up with service, but I took it in to the point of sale in the morning and they swapped the SIM card out and I went to a Genius Bar appointment to get the phone checked out. It is supposedly OK, but I am still having some problems when syncing it so I will have to visit the Genius Bar again tomorrow about that. At least I have not experienced the "no service" problem in the roughly 24 hours since the SIM card was replaced. (Fingers crossed)

  • My Iphone 4 will not start up, when i connect it to itunes i says : Activation error This device is not registered as part of the iPhone Developer Program.If you are a member of the Program, please register your device in the iPhone Developer Program Port

    my Iphone 4 will not start up, when i connect it to itunes i says : Activation error This device is not registered as part of the iPhone Developer Program.If you are a member of the Program, please register your device in the iPhone Developer Program Port

    Well, you downloaded a bootleg copy of iOS 7 beta and have installed it on your phone without being a developer. It has bricked your phone and you cannot get help here because doing what you did has voided your warranty. Have a nice day.

  • How long does it take to be an "official iPhone Developer?"

    I decided that I wanted to be a iPhone developer a couple of days after the March announcement. So I filled out the contact information, and of course got the reply that the beta program was full.
    Fast forward to July 14th, when I got a email from the iPhone Dev folks that my application was being reviewed. It is now July 26th, and I still haven't got an answer back. Does it really take this long to even become a developer??? Can someone get turned down? If so, why? Do you have to tell Apple what you plan to develop?
    I have never had to go through such hoops to become a developer for any other platform. You just pay your money and bang there your are, if you even need that. I'm not an official OS X developer because, I really don't need pre-released software.
    Also, since all I want to do is just run my own apps on my own iPhone/touch, do you really have to get the official stamp of approval for Apple to get a 'signature"? Do you have to go through Apple to even distribute your apps, even if you may or may not sell them?
    Finally, is there anyway to get a file to your iPhone application to read outside of adding it to your application's resources, or create a socket and read it in?
    Thanks,
    edji

    I signed up to be an iPhone developer two days ago and today I have my app running on my iPhone. It takes less than a day to get signed up. BUT, you need to watch out for one thing. When I originally placed my order for the $99 SDK I seemed to have checked some tax related checkbox I shouldn't have. The order completed as expected. But 36 hours later I had no email showing the order and I wasn't accepted yet. So I logged into my account on the Apple online store and looked at my order history. Sure enough, my order had a big red flag (not literally) stating I needed to fax in some tax exemption form. What? So I called the 800 number on the bottom of the screen. Since I'm an individual this shouldn't have been required. The guy on the phone sent me over to the small business dept who took care of the issue and the next day I had all my emails showing I was in the program.
    So if you sign up these days and it takes more than a day, check your order status.
    Enjoy,
    Rick

  • I'm stuck in iPhone Developer Program set up that i never started, how do I get my iPod to skip this and just work like normal?

    I'm stuck in iPhone Developer Program set up that i never started, how do I get my iPod to skip this and just work like normal?

    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    If recovery mode does not work try DFU mode.                         
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings

  • HT4061 I am receiving an Activation Error and unable to get into my phone.It's asking me to register my phone in the iPhone Developer program however I'm already registered. How do I move forward?

    I am receiving an Activation Error and unable to get into my phone.It's asking me to register my phone in the iPhone Developer program however I'm already registered. How do I move forward?

    Hi, jsgladden. 
    Here is an article I would recommend when experiencing issues activating a device.  The step referring to recovery mode usually resolves the issue.
    iPhone: Troubleshooting activation issues
    http://support.apple.com/kb/TS3424
    To retrieve your data, you will need to restore from backup after processing these steps.  Here is the article that walks you through restoring from either your iCloud or iTunes backup.
    iOS: How to back up and restore your content
    http://support.apple.com/kb/HT1766
    Cheers,
    Jason H.

  • The best way to get into Mac or iPhone Development?

    Hi, Ive been meaning to get into XCode and start developing for Mac and / or iPhone, but because ive been study for exams ive put it off. There finally over and I would love to dive into the development world. Ive done very basic programing before but that was a long time ago. So i guess what im getting at is where is the best place to start. I have no objective C or C knoledge but really would love to learn as I want career in software development primarily with apple products. I mean theirs loads of YouTube tutorials but yet I still get puzzeled. So any tips, advise etc would be much appriciatred 

    The vast majority of worthwhile content, docs, samples and tools are from Apple and available with a paid agreement.
    In the mean time, see:
    Stanford CS193P iOS 5: iTunes U  |  Assignments 
    Stanford CS193P iOS 4: iTunes U  |  Assignments
    As well...iPhone Developer Beginner Resource Guide

  • The device is not registered as part of iPhone Developer Program HELP! PLEASE! I WANT IT TO WORK!! I am not part of this program, how do I fixed it?

    I'm having some big issues with my iPod touch 4g. It is new and when I want to configure it, I can't because it appears this:
    "This device is not registered as part of the iPhone Developer Program. If you are member of the Program, please register your device in the iPhone Developer Program Portal at http://developer.apple.com/iphone/"
    Please I only want it to work. I am not part of the Developer Program

    I akready tried to restore it, but I cant it marks me error. Please, help me!

  • Need a tool to create Development and Test instance of a Production db

    I am very new to Oracle and have previously worked with SQL Server 2005/8 only.
    My current company only has one instance of the Oracle database (which is production) and until now, all development and testing used to take place on the same instance (what a mess!!).
    Anyways, we have now decided to create a development and test on a separate physical machine. We are on Oracle 11g on Windows 2008 Server.
    In SQL Server, it used to be fairly simple, just take a full backup of the database and restore it on another box with SQL Server and we had a new instance of the same database.
    Can someone point out a simple technique to create these development and test instance in Oracle. Essentially, we want to clone the database. Are there any tools available that can make this task simple.
    Thanks.

    Welcome the the forums !
    I believe this question is better suited to the "Database - General" forum (General Database Discussions but here is my take.
    You will first need to clone the Oracle binaries (ORACLE_HOME) - see MOS Doc 1154613.1 (Master Note For Cloning Oracle Database Server ORACLE_HOME's Using the Oracle Universal Installer (OUI))
    Then clone the database - see MOS Doc 458450.1 (Steps to Manually Clone a Database)
    HTH
    Srini

Maybe you are looking for