Last active
May 3, 2022 18:33
-
-
Save mmuszynski/ba6f7c443455553955bf0e4f12cc0a66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AnyMusicStaffViewElement: MusicStaffViewElement { | |
private var wrapped: MusicStaffViewElement | |
init(_ wrapped: MusicStaffViewElement) { | |
self.wrapped = wrapped | |
} | |
var unboxed: MusicStaffViewElement { | |
return self.wrapped | |
} | |
var asAnyMusicStaffViewElement: AnyMusicStaffViewElement { | |
AnyMusicStaffViewElement(self) | |
} | |
//MusicStaffViewElement protocol adoption | |
func path(in frame: CGRect) -> CGPath { | |
return wrapped.path(in: frame) | |
} | |
var aspectRatio: CGFloat { | |
return wrapped.aspectRatio | |
} | |
var heightInStaffSpace: CGFloat { | |
return wrapped.heightInStaffSpace | |
} | |
var anchorPoint: CGPoint { | |
return wrapped.anchorPoint | |
} | |
func offset(in clef: MusicClef) -> Int { | |
return wrapped.offset(in: clef) | |
} | |
func direction(in clef: MusicClef) -> MusicStaffViewElementDirection { | |
return wrapped.direction(in: clef) | |
} | |
} | |
//Tests | |
XCTAssertNotNil(MusicAccidental.natural.asAnyMusicStaffViewElement) //pass | |
XCTAssertNotNil(MusicAccidental.natural.asAnyMusicStaffViewElement.unboxed as? MusicAccidental) //pass | |
XCTAssertNotNil(AnyMusicStaffViewElement(MusicClef.bass) as? MusicClef) //fails | |
//Cast from 'AnyMusicStaffViewElement' to unrelated type 'MusicClef' always fails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment