Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LINQ on iOS???

Discussion in 'iOS and tvOS' started by Neotaku, Apr 2, 2011.

  1. Neotaku

    Neotaku

    Joined:
    Dec 8, 2010
    Posts:
    10
    With the new Unity release, LINQ is available for developing, but I'm not sure if it going to work on iOS. Can someone help me with this noob question? :) Thanks in advance!
     
    Gesin likes this.
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Haven't tested it lately but as it worked already during 3.0 prerelease when preorderers could use the beta, I would assume YES :)

    but its a matter of minutes to test it yourself if you want to be sure :)
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    LINQ works like a charm. So do default values for function parameters, extensions and everything else I have tried.
     
  4. Neotaku

    Neotaku

    Joined:
    Dec 8, 2010
    Posts:
    10
    Thanks guys :D
     
  5. japanitrat

    japanitrat

    Joined:
    Jul 7, 2011
    Posts:
    2
    Except for things like OrderBy (which is a Linq-extension on IEnumerator's), since code will be compiled at runtime. This is not allowed on iOS, therefore you will get Exceptions
     
  6. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    133
    I know this is an old topic, though I found something interesting. It seems you CAN use Linq on a List, but NOT on an array.
    When I tried to do "Input.touches.First(...)" I got an exception. Though when I first did "var touches = new List<Touch>(Input.touches)" and then use that, it did work perfectly. (Also "Input.touches.ToList(). ... doesn't work since that's again a Linq function on an array...)

    I haven't played around with all the Linq functions yet, but maybe someone can explain why this is?
     
  7. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I don't have an issue with .Where() on arrays.
     
  8. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    393
    I don't have an issue with OrderBy or OrderByDescending, but I did with ThenBy. So I suspect it's all implementation specific.
     
  9. JanWosnitza

    JanWosnitza

    Joined:
    Jun 23, 2012
    Posts:
    6
    "Input.touches" will be empty when there are no fingers touching the device AND First will throw an InvalidOperationException on empty enumerables. In this case you should use FirstOrDefault because it will return null on empty enumerables :)
     
    Last edited: May 9, 2013
  10. JanWosnitza

    JanWosnitza

    Joined:
    Jun 23, 2012
    Posts:
    6
    Extension functions like OrderBy will always be precompiled because the compiler already knows every Generic-Type (implicitly). This is only true for virtual/abstract generic functions (furthermore interface functions are always abstract).
     
  11. Anatolii_Landyshev

    Anatolii_Landyshev

    Joined:
    Aug 10, 2012
    Posts:
    31
    Most of Linq extension methods from Linq for Collections are not working with IEnumerables on iOS since they require AOT runtime compiler which is not supported.

    However there is a Linq for iOS library on Asset Store that is similar to Linq but doesn't require a runtime compiler. So you can use it on iOS.