Writing a UI in Xcode

How do you write code to create NSButton objects, NSTextField objects and other NSView subclasses and make them appear in a windows content view? Can someone show me some code to do that? Thanks!

1. Allocate and initialize the object.
2. Set desired properties.
3. Add it to a view in your app so the user can see it.
NSButton *btn = [[NSButton alloc] init]; // 1
[btn setTitle:@"The Button Title"]; // 2
// set frame, etc.
[myView addSubview:btn]; // 3
// don't forget to release btn before the pointer goes out of scope
Use the class references to find out the specifics of steps 1 and 2 for a particular object.

Similar Messages

  • How do I start writing Audio Units in Xcode 6?

    I just don't know where to start. Just want to make a simple dummy plugin - e.g. a gain plugin - for Logic Pro X.
    Can't make head or tails of the existing documentation for writing Audio Units - seems to be aimed at a totally different version of Xcode.
    Can anyone who develops Audio Units - or who understands the Xcode ecosystem - please advise?
    Thanks,
    Farhan

    https://developer.apple.com/mac/library/samplecode/PlayFile/Introduction/Intro.h tml
    Docs are your friend....mac os has it's own just like iPhone.

  • Question about Xcode from experienced Mac users

    Hi,
    I am new to Macs.Recently I found an issues where the finder copy certain files such as .DS_Store whenever I access a network share. I tried to use a command through the terminal but it didn't work. I called apple to ask if there was any way I could view the value of the com.apple.desktopservices preference (sorry if this is not the name) and they told me to install Xcode so I could see it.
    I am a network engineer but I could like to know how I could get benefit from Xcode. What does it do? Is there a way to access the same information using terminal?
    I would like to learn a bit more about things that can be done using the command interface. I would appreciate if you send me some links or recommend any books (for simple stuff)
    Thanks in advance for your opinion.
    Macbook C2D   Mac OS X (10.4.8)  

    Hello and welcome to Mac.
    Your ".DS_Store" issue is not really an issue, OSX creates the file wherever it goes. You can remove existing .DS_Store files on a volume of your choosing with this Applescript:
    Click here to launch Script Editor.
    display dialog "When you delete .DS_Store files, you will lose window size and icon arrangement for EVERY FOLDER on the target disk. Furthermore, if you had any Spotlight comments (a.k.a.Finder comments) associated with any files, they'll also be deleted"
    set mountedDisk to POSIX path of (choose folder)
    tell application "Terminal"
    if (count of windows) is 0 then do script ""
    delay 0.1
    do script "find " & quoted form of mountedDisk & ¬
    " -name .DS_Store -delete" in front window
    end tell
    Everyone you talk to at Apple is an idiot, don't waste your time. Preference files are binary files for faster reading and writing by software. Xcode contains an application called "Property List Editor" that translates the plist files from and to editable XML files when you open them. Believe it or not, you can download the application from this page:
    http://Gnarlodious.com/Computer?action=AttachFile
    But there are ways to write the preference to the file without editing it. You can persistently disable the creation of the offending files with this Terminal command:
    defaults write com.apple.desktopservices DSDontWriteNetworkStores true
    As for Xcode, it is for programmers. There isn't much value in it for a sysadmin. Terminal, however, should become your main tool. You can convert a binary plist file to XML with this Terminal command:
    plutil -convert xml1 ~/Library/Preferences/com.apple.desktopservices.plist ; cat ~/Library/Preferences/com.apple.desktopservices.plist
    That is actually two commands, the first converts the file, the second writes it to the Terminal. After editing it, you would convert the same file to binary with this command:
    plutil -convert binary1 ~/Library/Preferences/com.apple.desktopservices.plist

  • Help applescript and xcode

    hello community,
    i am writing a program  in xcode with applescript.
    the language itself causes no trouble to me, but
    how can i write values to the info.plist or a plist i
    created?
    the purpose is, that i can log settings done in the
    program itself.
    thanks
    DERand

    Are you talking about preferences, such as the User Defaults System?  Most of the existing Cocoa documentation can be used for ASObjC, you just need to know how to convert the examples.

  • Is it posible to get code::blocks on mac or is Xcode the best way of writing c   on a mac?

    Hey
    i was wondering whether xcode with all its compilcations is the best way of writing c++ on a mac or can you install other simpler compilers for begginers to c++ on mac because i have been having problems.
    thanks in advance for any answers

    Pease i would rely like to be writing some C++ and i would prefer not to be waisting my time if posible!!

  • Hello friends , I have started with writing  c code on mac using xcode .....but one of my friend told me to use gcc for coding. He started with terminal And used a text editor to compil the c program on his mac.. So please tell me how to do the same

    Hello friends , I have started with writing  c code on mac using xcode .....but one of my friend told me to use gcc for coding. He started with terminal And used a text editor to compil the c program on his mac.. So please tell me how to do the same and is there any pre stalled text editor on mac if yes then where and if no then which text editor to install and how to install gcc...please help me out thanks in advance !!!

    I have started with writing  c code on mac using xcode .....but one of my friend told me to use gcc for coding.
    Why? If you are developing and writing code on a Mac why would you not use the tools Apple has given you? And Xcode, once you get use to it, is a very nice development environment that will make you life a whole lot easier.
    If you insist on using an editor and the terminal I would recommend  Emacs   but it has a long learning curve so  something like TextWrangler  will work too.
    As for the compiler if you have Xcode installed install the command line tools and you will be able to compile from the terminal.
    good luck

  • New to Programming, need your help with writing code for java in Xcode.

    Hey everyone! Sorry if I sound like a total idiot here with a bunch of developers but I could really use your help. I am in college and having a bit of problems with my intro to programming class. The class is entirely Java based and so, after having to use dos windows on my grandpas crappy laptop I found out about xcode. I downloaded and installed it but I am having problems seeing where exactly it is that I am to write my code for a normal java application. Any help would be greatly appreciated! I wrote it on the bottom of a bunch of code that looked strange to me. For relatively simple java programs I chose the java application template. Is there something here that I missed?

    The Java Application project template looks like it sets up an application and some kind of starting UI using Swing/AWT. I didn't look at it too indepth, but if you are in an introductory course this might be more than you need to complete your assignments. There doesn't seem to be blank Java template, so I don't know what you should use. Perhaps just a blank project you add your .java files to.
    To answer where to write code, you would write it in your .java files under the /src folder. Execution begins in
    public static void main(String args[]) {}
    in YourAppName.java, then creates an object based on your application class, and runs the code from there to display the UI.

  • Problems reading from / writing to files in C on XCode 3

    Hi all,
    I'm a newcomer to C, having been learning for about a week and a half. All going well so far.
    I'm working through Dave Mark's 'Learn C on the Macintosh' e-book, and am up to Chapter 10, 'Working with Files.' Herein lies the problem.
    I can't get any of the file-related commands to work. The most basic, it seems, is 'fopen()'. There's a very simple demo program which is supposed to open an accompanying file ("My Data File.txt") which is in there with main.c and so on. Nothing happens, though. I've tried it with a 'w' mode parameter which should create the file if it doesn't already exist, but Spotlight can't find it if it is indeed being made.
    I'm using a fairly vanilla install of XCode 3, so I shouldn't have messed up the settings anywhere along the way. I've tried all of the different path types in the 'Get Info' dialogs, but still nothing.
    I guess that it's something very basic that I've missed or not understood. If any of you could take the time to help me out, it'd be much appreciated.
    If there's any further information you need, please just let me know.
    Many thanks,
    Pete.

    Ok I'm new to c programming and xcode and I have this same problem but the suggestions have not remedied my problem. I get this warning:
    "warning: no rule to process file '$(PROJECT_DIR)/operations.txt' of type text for architecture i386"
    This is my code
    #include <stdio.h>
    #include <math.h>
    int main()
    char filename[128],fvalue1[128];
    int x=0;
    FILE *input;
    printf("Enter name of file: ");
    fgets(filename,128,stdin);
    if((input = fopen(filename,"r"))==NULL)
    printf("Failed to open file.\n");
    x=1;
    if(x!=1)
    fgets(fvalue1,128,input);
    fclose(input);
    fflush(stdin);
    printf("\n\nPress enter to continue...");
    getchar();
    return(0);
    I think its a setting but I dont know what else to try.
    Any further input on this would be greatly appreciated. thanx

  • 2 simple questions on Xcode for the experts out there

    hey.  I have just started programming in C++ and am getting good results in the command line tool in xcode.
    I am trying out my own programmes based on what I am learning from a C++ book.  However, there seems to be an issue with one of the things I have learned.
    Acording to the book I can use a getline statement to allow a user to input a string with spaces such as a whole sentence instead of one word.
    Well when ever I use getline, xcode reports no errors (build succeeded) however it always skips over the getline and moves to the next part of the code.for example,
    #include <iostream>
    #include <string>
    using namespace std;
    //This is just a random example.
    int main ()
        string first;
        string last;
        cout <<"what is your first name?";
        cin >>first;
        cout <<"what is your middle and last name?";
        getline (cin, last);
        cout <<"hello"  <<first <<" " <<last;
        return 0;
    if it is my code please say.  But xcode only excepts my first name then skips right to hello. 
    It does not pause to let me input middle and last.  How can I fix this?
    Second question is I am viewing everything in the debug console.  How do I get my code to run in terminal?
    Thank you so much to everyone that answers.

    Saad Attieh wrote:
    So how do I get this to run in terminal.app? Will it run any differently?
    That is how I ran it. It runs the same.
    The easiest way is to just inspect the build output , find the temporary path it uses, and go there. For simple programs like this, you can just type them in with vi and compile with clang++.
    Oh yeah and do you know if and how I can use c++ to create a full application in Xcode?  As in what template do I choose?  According to the user guide I have to choose a carbon application template or something like that if I want to make a application with the usual quit and minimise etc buttons.  But I cannot find that so I am feeling very silly.
    Also, looking a head into the future what are the best languages to use for coding in Mac OS X?
    You should use Objective-C for building MacOS X programs. If you are building command line tools or libraries, you could just use C++. There isn't anything on the Mac that requires C++.
    If you really wanted to, you could write the Mac parts in Objective-C and your own routines in C++ and connect them with C linkage. Another option would be to use Objective-C++. The core operating system and especially user interface libraries are all designed for Objective-C. It isn't smart to fight against the system.
    In practice, C++ is just an awful language. Anything you might want to use C++ for can be more easily done in Objective-C. I spent 15 years writing C++ software. I really enjoyed it, but I realized that I enjoyed it because it was hard - like a puzzle. That approach isn't conducive to effective software development.

  • Socket problem after upgrading to Xcode 4.2 and Mac OS 10.7.2

    Hi,
    I am writing a client app to connect to a java server using the method explained in http://developer.apple.com/library/ios/#qa/qa1652/_index.html
    Everything was working fine until I upgraded to Xcode 4.2 and Mac OS 10.7.2 yesterday.
    The server cannot read data written by the client. Attempting to read returns -1 which means end of stream.
    Any idea why this has happened?
    Thanks.

    Please ignore this post. It was a problem in my code.

  • Xcode, how do you take an app from an idea to a data model, data structure, or class structure?

    Hey everyone!
    I'm a beginner xcoder and computer engineering sophomore and have literally spent every hour of the past few weeks reading as much as I possibly can about becoming a developer.
    I've found plenty of documentation, and guides on how to do very specific things in xcode and objective-C but am still looking for more information on one topic; how do you decide which data models/structures/controllers etc to use?
    I mean, you personally. I've been looking for a resource on this and have not been able to find one. I just finished Apple's iOS Developers Guide and they mention "choosing a data model" but do not describe them in much detail.
    The following is what is provided in the guide:
    ● Choose a basic approach for your data model:
    ● Existing data model code—If you already have data model code written in a C-based language, you
    can integrate that code directly into your iOS apps. Because iOS apps are written in Objective-C, they
    work just fine with code written in other C-based languages. Of course, there is also benefit to writing
    an Objective-C wrapper for any non Objective-C code.
    ● Custom objects data model—A custom object typically combines some simple data (strings, numbers,
    dates, URLs, and so on) with the business logic needed to manage that data and ensure its consistency.
    Custom objects can store a combination of scalar values and pointers to other objects. For example,
    the Foundation framework defines classes for many simple data types and for storing collections of
    other objects. These classes make it much easier to define your own custom objects.
    ● Structured data model—If your data is highly structured—that is, it lends itself to storage in a
    database—use Core Data (or SQLite) to store the data. Core Data provides a simple object-oriented
    model for managing your structured data. It also provides built-in support for some advanced features
    like undo and iCloud. (SQLite files cannot be used in conjunction with iCloud.)
    ● Decide whether you need support for documents:
    The job of a document is to manage your app’s in-memory data model objects and coordinate the storage
    of that data in a corresponding file (or set of files) on disk. Documents normally connote files that the user
    created but apps can use documents to manage non user facing files too. One big advantage of using
    documents is that the UIDocument class makes interacting with iCloud and the local file system much
    simpler. For apps that use Core Data to store their content, the UIManagedDocument class provides similar
    support.
    I suppose my question boils down to, how do you decide which structures to use? If you can provide an example of an app idea and how its implemented that would be very helpful and much appreciated!
    For example, to implement the idea of an app which allows users to progress through levels of knowledge of a certain subject and rewarding them with badges and such (this is not an actual app just a whim) how would one model that?
    Thanks in advance for all your help!!!

    SgtChevelle wrote:
    how do you decide which structures to use?
    Trial and error.
    I wish I had a better answer for you, but that pretty much encapsulates it. There is some, but not much, good wisdom out there, but it takes a significant amount of experience to be able to recognize it. The software development community if currently afflicted with a case of copy-and-paste-itis. And the prognosis is poor.
    The solution is to be brutal to yourself and others. Focus on what you need and ignore everything else. Remember that other people have their own needs and methods and they might not be applicable to you. Apple, for example, can hire thousands of programmers, set them to coding for six months, pick the best results, and have the end-users spend their own time and monety to test it. If you don't have Apple's resources and power, think twice about adopting Apple's approach. And I am talking from a macro to a micro perspective. Apple's sample and boilerplate code is just junk. Don't assume you can't do better. You can.
    Unfortunately, all this takes time and practice. You can read popular books, but never assume that anyone knows more than you do. Maybe they do and maybe they don't. It takes time to figure that out. Just do your best, ignore the naysayers, and doubt other people even more than you doubt yourself.

  • CollectionView tutorial, Xcode crashes 100% of the time

    I'm writing a document-based application using a CollectionView in each document. Following the guide
    http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Collectio nViews/
    with the only modification in using the NSDocument subclass to hold the NSMutableArray, instead of the App Delegate as suggested (since there is no App Delegate in the template). In the "Bind the Views to the Data" stage, when I attempt to bind any object in the collection view item view, Xcode (4.1 on Lion) crashes whenever I select "Collection View Item" from the drop down in the bindings tab. This crash would occur every attempt without exception, on multiple Macs (early-2010 iMac, mid-2009 MacBook aluminium). Anyone else seeing this? Perhaps know a way around it?

    This is not an answer, but a potential path.   There are far more discussions and far more developers following on the Apple mailing lists (the Xcode list, for this case) or in the Developer forums, than are here in the Apple Support Communities.  (The developer mailing lists are open, and the list archives contain a wealth of information.  The Apple developer forums require developer program membership for access.)  And the usual suggestion applies: log a bug report via radar.
    And while I don't think it'll help, you might be asked to uninstall Xcode and then reinstall it.  Sometimes Xcode can get itself tangled up after an upgrade.

  • Placing Images within a View in XCode

    Hello, I am new to XCode and Mac Application design, but I need to code a program where a user can click with the mouse and an image will appear where the user has clicked. My main issue (I think) is writing code that places these images in the view as the user clicks. Could someone help me with this? I am currently using XCode 4.

    Hi Mohler,
    PAL is ultimately some set of database procedures . If you want to use it as HANA View, you may need to right scripted views and consume the same.
    Analytic views are typically defined on at least one fact table that contains transactional data. Using analytic views you can create a selection of measures—sometimes referred to as key figures—, add attributes and join attribute views. Analytic views leverage the computing power of SAP HANA to calculate aggregate data, e. g., the number of cars sold per country, or the maximum power consumed per day.
    Ref : https://cookbook.experiencesaphana.com/bw/modeling-data/modeling-concepts/views/
    Sreehari

  • Lock screen in Xcode

    Hello
    I'm new in Xcode. I would like to make an Lock Screen application.
    How can I tell the textfield that when the word 'test' is entered, the program closes.But if Ienter a different word should appear a message.
    Example code would be helpful.
    Thanks
    Mario

    For the target application, you'll want to use the frameworks; without intending offense, the only folks that ask for and process passwords directly are usually folks that are trying to steal the user's passwords.  The following is an OpenGL framework for a screensaver: Writing a Screen Saver (part I), Writing a Screen Saver (part II) and here is part of the Apple screen saver framework documentation.  That'll get you some idea of what's involved with using the existing frameworks available here.  Now in fairness, this probably really isn't what you want, if you're just learning Cocoa...
    If you're looking to display a dialog box or other window and prompt for input and react to it (and I'd stay away from the "passwords" stuff for now; you're writing the first part of a Guess The Animal-style program, or whatever), that's a fairly straightforward Cocoa application.
    Posting an example of what you want is slightly difficult, as the easiest way to do most of what you're after is with the Interface Builder tool and that doesn't post well here; a fair chunk of the generic prompting application is "just" making the connections in IB.  (The amount of source code to do the simplest form of string comparision is a couple of lines around the NSString's isEqualToString method (there's some example code lined at the end of the isEqualToString method definition) as the core test.
    If you're new to C and/or Objective C and/or Cocoa programming, I'd suggest one of the available books on Cocoa and Mac OS X programming.  There are various guides and Apple intro material including Your First Mac App, and both Big Nerd Ranch and Pragmatic Programmers have programming books available, and there is online materials such as this course at CocoaDevCentral - that last course is a bit stale, as Xcode has been a moving target recently.)
    And there's a veritable goldmine of sample application code available directly in the Xcode-provided documentation.
    There is far more development-related traffic in the Apple Developer (Discussion) Forums, and particularly on the various mailing lists including the Cocoa mailing list and particularly in the archives of the mailing list.

  • XCode Tools  Ok to remove from Hard Disk?

    Hello,
    In order to free us some room on my hard disk, I'm wondering if it's ok to remove the XCode Tools from the "Installers" folder (Applications/Installers/XCode Tools/)
    As far as I can see, these tools have yet to be actually installed but it's difficult to be sure. I have no need of any code writing tools at this time.
    Any advice welcome.
    Cheers,
    Jeff
    eMac 1.25 GHz USB 2.0 1Gig RAM   Mac OS X (10.3.9)  

    Mac OS X does not require the Xcode tools to operate
    correctly.
    (20165)
    Thanks
    It's a bit confusing to me as to whether the XCode Tools are ialready installed or have yet to be installed. I'm leaning towards "yet to be installed" since they are in the /Applications/Installers/ folder. I'd just like to be certain before I remove them.
    Cheers
    Jeff

Maybe you are looking for

  • Why are PDF attachments are showing up on the body of emails, instead of as actual attachments?

    PDF attachments are showing up in the body of my emails rather than as attachments. I need to be able to open them in other programs, eg notability, mad can't do that if they're not real attachments. On my other devices they're showing up at regular

  • How to Make Link Open an Attached PDF?

    I see in "Link Properties" and "Actions" that there is an option to "Open a file"; but when I select this, and click "Add"--I am not given the opportunity to link to the other PDF file that is already attached to the PDF file that I'm working on. I k

  • OIM task Assignment Tab

    I am trying to understand how the assignment tab works. In process Def, I have a task, like create user. That has a assignment tab which has one entry in it. It has escalation time and a Default Rule. I entered an escalation time of 10 mins and then

  • How do I reinstate toolbars that have been removed from my browser?

    I wish to reinstate the toolbars on my browser, they have all been removed and i cannot view any of them. == Yesterday == == User Agent == Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729;

  • Flip Video camcorder and iPhone

    Can anyone explain why video that's shared by email via the camera's Flipshare to iPhone cant be played back on the iphone ?? Can this issue be overcome...if so, how ?