How to modify source in ARC?

Discussion in 'iOS Programming' started by mikezang, Jun 4, 2012.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I tried to use a open source FPPopover, but it doesn't support ARC, how can I modify it for ARC easily?
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    You can do it easier.
    Go to your Proejct, go to your target, then "Build Phases" Tab, then to the Compile Sources ->
    Find the code files of the library you are trying. and double click on it, you will be able to insert compiler flags.
    Type in here
    Code:
     -fno-objc-arc
    If you add that, it won't try to do ARC compiling on these files :)
    Or you can just convert the files to ARC with the build in ARC-Converter ;p
     
  3. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #3
    Thanks, I did it but I found the warning is due to static analyzer as below:
     

    Attached Files:

  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    This has not much to do with the ARC, but more with the code that's badly written :) (I think, i just took a quick glance)
     
  5. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #5
    The problem with directions looks strange at first because I don't have all of the code, but the second problem is related to ARC and he needs to use one of those bridging casts for objects created with CoreFoundation. Maybe __bridge_retained in this case, but I still don't use ARC so I'm not sure.
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    The analyzer is complaining that the method returns an owned object rather than an autoreleased object but the name of the method doesn't indicate that it's returning an owned object. This isn't related to ARC.

    Is the returned path CFReleased somewhere else in the code? If so you could fix this by changing the name to start with new.

    UIBezierPath is similar to CGPath and the code could probably be rewritten to use UIBezierPath without much difficulty. If so it would then use Cocoa memory management and not CF memory management. I don't think CGPath is toll-free-bridged with an Objective-C class so there isn't a one-line change for this.
     
  7. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #7
    Strange, I was sure ARC would let you use CF objects, you only need to use one of those casts, like __bridge_retained or __bridge_transfer. Here the path is created with the call to CGPathCreateMutable() and since he can't change the name of that function what else could he do?
     
  8. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    I'm willing to be proven wrong. What class would be toll-free-bridged to the CGPath?
     
  9. idelovski, Jun 5, 2012
    Last edited: Jun 5, 2012

    idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #9
    Well, seems like I misinterpreted intentions of the method on those three images. It was actually expected to return a new retained object and not autoreleased one. Since the word 'create' is not one of those magic keywords (new, alloc, copy and mutableCopy) he really needs to change the method name so it starts with 'new'.

    Must admit I have several methods that do exactly the same thing: They start with the word create and return - what else but CGPathRef. Now I see why were you talking about toll-free bridging. In order to autorelease it I would need an equivalent cocoa object. Ah. Now I need to change those method names in my own code.

    And now I see where I picked the habit of using such naming convention: Programming with Quartz. They do it all the time. All the functions that create new CoreGraphics objects start that way. As I was converting them into Obj-C methods I kept the similar name and now I have the problem.
     

Share This Page