Limiting which frameworks or APIs can be used in source?

I'm wondering if there is a way to limit the usage of a list of frameworks or APIs.

Take for example a class-room with shared computers where students will use SPM to create CLI programs to learn programming (i.e. not iOS development).

Is there a way to limit the compiler or somehow (at compile or even runtime) say - this code should not be able to load CoreData or Foundation.URLSession :thinking:

Even if something that is not completely secure is OK, I'm just trying to to come up with valid ideas atm.

Could swizzling be used to prevent certain types from being created? Giving a runtime error if they are?

I guess there must also be a way to dynamically check whether a framework is loaded. Not certain how, though.

If the code doing this was made in objective c I guess you can even use the dynamic loading static method to have all of this swizzling run automatically just by linking to your framework?

Yes, swizzling is definitely something on my mind - it might a LOT of code though to swizzle every method in CoreData for example ... and that still doesn't take care of any global functions (if I remember right, didn't swizzle for many years).

Regarding Core Data, perhaps you could again use Objective-C to test if a class defined in Core Data is present at runtime using NSClassFromString?

if (NSClassFromString(@"SomeCoreDataClass") != nil) {
   fatalError("Please refrain from using Core Data")

That's a neat direction ... maybe I could couple this with the new SPM plugin system to inject runtime checks like this while compiling the binary.

1 Like
Terms of Service

Privacy Policy

Cookie Policy