Bundle.main.path(forResource:ofType:inDirectory:) returns nil

后端 未结 10 2443
遥遥无期
遥遥无期 2020-12-07 13:08

Try not to laugh or cry -- I\'m just getting back into coding after 20 years out...

I\'ve spent more than 4 hours looking at references and trying code snippets to g

10条回答
  •  猫巷女王i
    2020-12-07 13:34

    Ah, so just found myself dealing with the exact same problem as the OP.

    The problem is that the solutions given here and here do not work when the code is being executed in a playground, since the Options menu of add files looks different for it does not show the Add to targets field:

    When inside a .playground file, instead press the Hide or show the Navigator button on the top-right of your Xcode window (visual impression)-->

    Then, once the Navigator folds open on the left-side of the Xcode window, simply drag & drop your file to the Resources directory of your playground.

    If your setup looks anything like the following you should be ok:

提交回复
热议问题