Can an iPhone get infected will malware by sharing a wifi connection with an infected computer?
In theory any computer (including smartphones) is attackable over WiFi (or any other channel) as long as software has bugs which can be exploited to do so. Having a infected MacBook to start with, or sharing the AppleID between devices, may make it easier (or open additional attack vectors), but at the end it's always a weakness on the attacked device which makes it possible.