Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

func load save button on swift

massimonegro204massimonegro204 Posts: 61New Users @
edited September 2014 in iOS SDK Development
If I have this in Object-C

- (void)loadSavedButtons
{
    NSUserDefaults *userDeault = [NSUserDefaults standardUserDefaults];
    int number = [userDeault integerForKey:@"NumberOfButton"];
    if (number != 0) {
           self.CountScenario = number;
        for (int i=0; i < number; i++){
        UIButton *newButton  = [self createButtonWithIndex:i];
            [self.view addSubview:newButton];
            NSLog(@"number %i",i);
        }
       }


how can I make in swift ?
Post edited by massimonegro204 on

Replies

  • dev666999dev666999 Posts: 3,621New Users @ @ @ @ @
    Break it down to its parts...

    search...

    NSUserDefaults in Swift
    For loop in Swift
    UIButton in Swift
  • massimonegro204massimonegro204 Posts: 61New Users @
    edited September 2014
    I intend to call it as a function EG.
    
    func loadSavedButtons () {
    var number = BLA BLA
     if (number != 0) {
    CountScenario = number
    for (var i=0; i < number; i++) {
    let button = ______   [self createButtonWithIndex:i];___ 
             self.view.addSubview(button)
     }
            }
    
    
    Post edited by massimonegro204 on
  • massimonegro204massimonegro204 Posts: 61New Users @
    edited September 2014
    how can I do to ?
    With :
    [self createButtonWithIndex:i];
    
    Post edited by massimonegro204 on
  • massimonegro204massimonegro204 Posts: 61New Users @
    edited September 2014

    sorry !!!
    Post edited by massimonegro204 on
  • dev666999dev666999 Posts: 3,621New Users @ @ @ @ @
    I wouldn't be able to help you with Swift, because I have not learned it yet. The reason for my previous answer was that is how I learned to program in Java. Android's native language is Java. I didn't know the language. So when I needed to convert an app to Java, that's how I did it. Piece by piece. You should be able to do the same with Swift.
  • massimonegro204massimonegro204 Posts: 61New Users @
    as you can see we are able to do it piece by piece but I miss that code !!!!
    excuse me but if CreateButtonWithIndex
    creates buttons how can I do to bring this code

    [self createButtonWithIndex:i];
    
    from Object-C to Swift
  • dev666999dev666999 Posts: 3,621New Users @ @ @ @ @
    edited September 2014
    This link has an example of what you're trying to do.

    Search the page for "Index" and you will see the code.

    http://www.cs.cornell.edu/jif/swift/doc/
    Button newButton = new Button("" + i, "?");
    
  • massimonegro204massimonegro204 Posts: 61New Users @
    edited September 2014
    i tried in this mode
    var newButton6: () = CreateButtonWithIndex(i)
    
    but this creates one button but it does not create as many buttons as the value of the i
  • massimonegro204massimonegro204 Posts: 61New Users @
    edited September 2014
    i should do for i
Sign In or Register to comment.