Skip to content

Latest commit

 

History

History
44 lines (36 loc) · 1.1 KB

readme.md

File metadata and controls

44 lines (36 loc) · 1.1 KB

CCPreviewDevice

Simple enum to be used when previewing SwiftUI view in a specific device.

Usually you have to do something like this:

#if DEBUG
struct LandmarkList_Previews : PreviewProvider {
    static var previews: some View {
        
        ForEach(["iPhone 8", "iPhone XS Max"].identified(by: \.self)) {
            deviceName in
			SomeView()
            .previewDevice(PreviewDevice(rawValue: deviceName))
        }
    }
}
#endif

In order to specify devices, you need to use error prone string name. Instead of that you can do something like this:

#if DEBUG
struct LandmarkList_Previews : PreviewProvider {
    static var previews: some View {
        
        ForEach([CCPreviewDevice.iPhone8.rawValue, CCPreviewDevice.iPhoneXsMax.rawValue].identified(by: \.self)) {
            deviceName in
            LandmarkList()
            .previewDevice(PreviewDevice(rawValue: deviceName))
        }
    }
}
#endif

Usage

Just drag&drop CCPreviewDevice.swift into your project and you're ready to go.

License

MIT License.