Codea 3.5 version (316)

@UberGoober Even if you don’t have access to the enums, you can use or combine their integer values instead. See the third example in the documentation for objc.cls where I’m combining three enum values.

My app crashes consistently when returning to the editor after running ok-no idea why? Sent a crash log.

@piinthesky Are you using the new objc feature?

No, just my previously working code.

@dave1707 - couldn’t see you code working. Tried modifying to the code below but brightness didn’t seem to change ?. Do we need to init the calls in some way ?


viewer.mode=STANDARD

function setup()
    fill(255)
    parameter.number("bright",.2,.8,.5)
    brightness=objc.cls.UIScreen.mainScreen.brightness
end

function draw()
    background(255, 0, 230)
    text(bright,WIDTH/2,HEIGHT/2)
end

function touched(t)
    if t.state==BEGAN then
        objc.cls.UIScreen.mainScreen.brightness=bright
    elseif t.state==ENDED then
        bright=objc.cls.UIScreen.mainScreen.brightness
    end
end


All,

Had a funny recently on the forum. When I have created a new post and tapped post comment it seemed to hang up, a second tap on post comment shifted to a blank page with a new blank editing box at the top. Anyone else seen this?

p.s. that’s on my iPad.

@Bri_G I loaded your version and when I changed the slider and tapped the screen, I could see the screen brighten or darken depending on the slider value.

@dave1707 - doh, forgot to tap the screen. Naively thinking changing the slider would respond the same. Thanks for the post.

@UberGoober I found at least two issues in our objc implementation which I’ll be fixing shortly. In the meantime, you can try the following code:

    local uiView = objc.cls.UIViewController()
    local application = objc.cls.UIApplication:sharedApplication()
    local window = application.keyWindow;
    local root = window.rootViewController;
    local presented = root.presentedViewController.presentedViewController;    
    presented:presentViewController_animated_completion_(uiView, false, function() end)
end

@piinthesky I just checked out the logs, there is no crash stack which makes me concerned. Is it caused by a project small enough to share that we can use to reproduce?

@jfperusse oh right, duh, enums are just ints. Thanks for reminding me.

@UberGoober Finally managed to add a dynamically created UIView. Had to do various fixes so this will only be possible in the next beta version.

The new beta will also include a fix to prevent crashes when invoking a method with the wrong type of arguments, as well as some validation and error messages.

Here’s the code I’ve been able to use on my iPad after the fixes:

    local view = objc.cls.UIView:alloc():initWithFrame_(objc.rect(100, 100, 100, 100))
    view.backgroundColor = objc.cls.UIColor:redColor()
    local application = objc.cls.UIApplication:sharedApplication()
    local root = application.keyWindow.rootViewController
    root.presentedViewController.presentedViewController.view:addSubview_(view)

@jfperusse i think the callback docs need fixing because it says to use prefixes like o for objects and b for bools but the example shows “objError” and “boolGranted”

also the classes that we can use should be listed somewhere, i already tried a couple that don’t exist, and using “UIScreen” for an example is confusing since there is no reference or search results for UIScreen in the technologies page of apple, you have to dig down to UIKit and then click Windows and Screens to find it

also, why not just remove underscores completely from the methods?

@Simeon its my large km3net app, which is quite complicated! What would be the best way to share it with you?

@piinthesky Would you be able to post the zip file here. I could try it to see if I get the same results on different iPads.

@skar that’s my fault, the docs are correct (you only need a single character) but I prefer the readability of writing a short word that begins with that character (o = obj, b = bool, etc)

On methods with underscores, in Objective-C the colons (:) are part of the method name. So setSpeed:withObject: takes two arguments, and is distinct from the method named setSpeedwithObject (no arguments). In order to represent this in Lua @jfperusse maps the colons to underscores

@piinthesky you could email me (simeon@twolivesleft.com) and share it as a zip or iCloud link. If it has dependencies then I’d need to use those too

Hi @skar! Sorry for the confusion in argument names. As Simeon mentioned, we went for an hybrid method where only the first 1 or 2 characters are really important, so you can choose between “oError” or “objError” based on your personnal preference. I could add a “Naming Convention” section to the documentation explaining that both options are possible.

As for listing all possible classes, there would be too many, you do need to know what you’re trying to implement, but we could actually list the included frameworks (UIKit, Game Controller, User Notification, etc.).

@jfperusse that code works a treat! This is so cool.

Also much thanks for the improved error handling.

The very first thing I thought of when I saw this was how I’ve wanted a gui to save and load files since forever, so after I got your example working I immediately tried to implement a document picker:


        --[[
        
        ***Objective-C example I found:
        
        ** Create the array of UTI Type that you want to support
        * Pass the array of UTI Type that application wants to support. Add more UTI Type if you want to support more other than listed
        */
        —(According to the Swift example below it should be possible to simply use [“public.text”] here too)

        NSArray *types = @[(NSString*)kUTTypeImage,(NSString*)kUTTypeSpreadsheet,(NSString*)kUTTypePresentation,(NSString*)kUTTypeDatabase,(NSString*)kUTTypeFolder,(NSString*)kUTTypeZipArchive,(NSString*)kUTTypeVideo];
        
        //Create a object of document picker view and set the mode to Import
        UIDocumentPickerViewController *docPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:types inMode:UIDocumentPickerModeImport];
        
        //Set the delegate
        docPicker.delegate = self;
        
        ***Swift example I found:
        
        UIDocumentPickerViewController(documentTypes: ["public.text"], inMode: UIDocumentPickerMode.Import)
        documentPicker.delegate = self
        
        ]]
        
        local application = objc.cls.UIApplication:sharedApplication()
        local window = application.keyWindow;
        local root = window.rootViewController;
        local presented = root.presentedViewController.presentedViewController; 
        local picker = objc.cls.UIDocumentPickerViewController_initWithDocumentTypes_inMode_({"public.text"}, 0) 
        picker.delegate = presented
        presented:presentViewController_animated_completion_(picker, false, function() end)

…needless to say, it didn’t work. I’m not sure if instantiating a C array for a parameter is possible, for one thing, but the initialization call itself doesn’t seem to be right either.

Is this possible?

@UberGoober You almost got it right! Try this:

    local application = objc.cls.UIApplication:sharedApplication()
    local window = application.keyWindow;
    local root = window.rootViewController;
    local presented = root.presentedViewController.presentedViewController; 
    local picker = objc.cls.UIDocumentPickerViewController:alloc()
    picker:initWithDocumentTypes_inMode_({"public.text"}, 0) 
    picker.delegate = presented
    presented:presentViewController_animated_completion_(picker, false, function() end)

OMG it works. I can see no further use for sliced bread!!

Okay so I would never have been able to figure this out on my own without two crucial pieces of information that imho need to be in the documentation:

  • the pattern for typing multiple parameter names—I did figure this out myself through a lot of trial and error, eventually, but I already have some objc experience, so I think an example in the docs is really needed
  • the alloc pattern for accessing complex initializers. Imho this is really necessary to include as an example, because so many classes require it.