Skip to content

Instantly share code, notes, and snippets.

@marty-suzuki
Created July 23, 2016 07:03
Show Gist options
  • Save marty-suzuki/c1f52ff0c0ece682564fe445f82f1c12 to your computer and use it in GitHub Desktop.
Save marty-suzuki/c1f52ff0c0ece682564fe445f82f1c12 to your computer and use it in GitHub Desktop.
class SectionLayoutManager {
//MARK: - Inner Enums
enum LayoutType {
case Profile
case ProfileFollowing
case ProfileFollower
case ProfileFollowingFollower
init(followingCount: Int, followerCount: Int) {
if followingCount > 0 && followerCount > 0 {
self = .ProfileFollowingFollower
} else if followingCount > 0 && followerCount < 1 {
self = .ProfileFollowing
} else if followerCount > 0 && followingCount < 1 {
self = .ProfileFollower
} else {
self = .Profile
}
}
}
enum SectionType {
case Profile
case Following
case Follower
case Unknown
}
//MARK: - Static constants
private static let ProfileLayout: [SectionType] = [
.Profile
]
private static let ProfileFollowingLayout: [SectionType] = [
.Profile, .Following
]
private static let ProfileFollowerLayout: [SectionType] = [
.Profile, .Follower
]
private static let ProfileFollowingFollowerLayout: [SectionType] = [
.Profile, .Following, .Follower
]
private static let SectionLayoutList: [LayoutType: [SectionType]] = [
.Profile : ProfileLayout,
.ProfileFollowing : ProfileFollowingLayout,
.ProfileFollower : ProfileFollowerLayout,
.ProfileFollowingFollower : ProfileFollowingFollowerLayout
]
//MARK: - Properties
private var layoutType: LayoutType = .Profile
var numberOfSections: Int {
return self.dynamicType.SectionLayoutList[layoutType]?.count ?? 0
}
subscript(index: Int) -> SectionType {
return self.dynamicType.SectionLayoutList[layoutType]?[index] ?? .Unknown
}
func setup(followingCount followingCount: Int, followerCount: Int) {
layoutType = LayoutType(followingCount: followingCount, followerCount: followerCount)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment