### Install SwiftGanZhi using Swift Package Manager Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Instructions for adding the SwiftGanZhi library to your project using Swift Package Manager. This involves updating your Package.swift file or using Xcode's package management interface. ```swift dependencies: [ .package(url: "https://github.com/YOUR_USERNAME/SwiftGanZhi.git", from: "1.0.0") ] ``` -------------------------------- ### Basic GanZhi Four Pillars Calculation in Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Demonstrates how to get the Four Pillars (Year, Month, Day, Hour) for a given date using the SwiftGanZhi library. This example uses Mean Solar Time. ```swift import GanZhi // Initialize a Date (using the provided helper or standard methods) let date = Date(year: 2024, month: 2, day: 4, hour: 16, minute: 30)! // Get Four Pillars directly from Date let pillars = date.fourPillars() print(pillars.description) // Output: 甲辰年 丙寅月 戊戌日 庚申时 ``` -------------------------------- ### Register Custom Global Situation Rule - Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Allows users to define custom rules for detecting global situations in SwiftGanZhi, supporting different schools of thought. This example demonstrates registering a 'Pure Yang' rule that checks if all stems and branches in the chart are Yang. Once registered, the rule is automatically evaluated when accessing `.allGlobalSituations`. ```swift // Register a "Pure Yang" rule GlobalSituationRegistry.register("Pure Yang") { pillars in let stems = [pillars.year.stem, pillars.month.stem, pillars.day.stem, pillars.hour.stem] let branches = [pillars.year.branch, pillars.month.branch, pillars.day.branch, pillars.hour.branch] return stems.allSatisfy { $0.yinYang == .yang } && branches.allSatisfy { $0.yinYang == .yang } } // The rule will be automatically checked when calling .allGlobalSituations ``` -------------------------------- ### Advanced GanZhi Four Pillars with True Solar Time in Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Shows how to calculate GanZhi Four Pillars considering True Solar Time, which requires specifying the location's longitude. This example demonstrates the correction of the hour pillar based on longitude. ```swift import GanZhi // Birthplace: Urumqi (Longitude 87.6°), Time: Beijing Time 10:00 let date = Date(year: 2024, month: 6, day: 15, hour: 10, minute: 0)! let urumqi = Location(longitude: 87.6, timeZone: 8.0) // Get corrected pillars let pillars = date.fourPillars(at: urumqi) print(pillars.hour.character) // Original 10:00 is Si Hour (Snake) // Corrected time is approx 07:50, which is Chen Hour (Dragon) ``` -------------------------------- ### Configure Language for Internationalization - Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Supports internationalization (i18n) with Simplified Chinese (default), Traditional Chinese, Japanese, and English. This example shows how to switch the language configuration to English and then prints the character for 'Jia' stem and the name for 'Friend' Ten God, demonstrating localized output. ```swift // Switch language GanZhiConfig.language = .english let stem = Stem.jia print(stem.character) // Output: "Jia" let tenGod = TenGods.friend print(tenGod.name) // Output: "Friend" // Note: Use .name or .description properties instead of .rawValue to get localized strings. ``` -------------------------------- ### Calculate Major Luck Cycles (Da Yun) with Swift Source: https://context7.com/mazeye/swiftstembranch/llms.txt Calculates the start age and generates Major Luck Cycles (10-year periods) for a BaZi chart based on birth date and gender. It also allows for calculating Annual Luck (Liu Nian) within each cycle. ```swift import GanZhi let birthDate = Date(year: 1984, month: 5, day: 20, hour: 14, minute: 30)! let pillars = birthDate.fourPillars() // Create luck calculator with gender let calculator = LuckCalculator(gender: .male, pillars: pillars, birthDate: birthDate) // Calculate start age (when first luck cycle begins) let startAge = calculator.calculateStartAge() print("Start Age: (String(format: "%.1f", startAge)) years") // Generate major luck cycles (default: 10 cycles) let cycles = calculator.getMajorCycles(limit: 8) for cycle in cycles { print(cycle.description) // e.g., "丙寅运 (起运: 3.4岁, 1987-1996)" // Access cycle details print("Stem-Branch: (cycle.stemBranch.character)") print("Start Age: (cycle.startAge)") print("Years: (cycle.startYear)-(cycle.endYear)") // Calculate Annual Luck (Liu Nian) within cycle for year in cycle.startYear...cycle.endYear { let offset = year - 1984 var index = offset % 60 if index < 0 { index += 60 } let yearSB = StemBranch.from(index: index) print(" (year): (yearSB.character)") } } ``` -------------------------------- ### Calculate Luck Cycles and Annual Luck - Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Calculates the start age, major luck cycles (Da Yun), and derives annual luck (Liu Nian). It initializes a LuckCalculator with gender, pillars, and birth date. The code iterates through cycles and years to determine Stem-Branch and age for each year. ```swift let calculator = LuckCalculator(gender: .male, pillars: pillars, birthDate: date) // 1. Get Start Age let startAge = calculator.calculateStartAge() print("Start Age: (startAge)") // 2. Get Major Cycles (Default: 10 cycles) let cycles = calculator.getMajorCycles() for cycle in cycles { print(cycle.description) // e.g. "Bing-Yin Cycle (Start: 3.4 yrs, 1987-1996)" // 3. Derive Annual Luck (Liu Nian) // Iterate through years in the cycle for year in cycle.startYear...cycle.endYear { // Calculate Stem-Branch for the year // 1984 is Jia-Zi (Index 0) let offset = year - 1984 var index = offset % 60 if index < 0 { index += 60 } let yearSB = StemBranch.from(index: index) let age = year - Calendar.current.component(.year, from: date) print(" (year) (yearSB.character) (Age: (age))") } } ``` -------------------------------- ### Hidden Stems and Ten Gods Analysis in SwiftGanZhi Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Illustrates how to access the hidden stems (Main, Middle, Residual Qi) within a branch and their corresponding Ten Gods using the SwiftGanZhi library. This provides a deeper analysis of the branch's composition. ```swift let pillars = date.fourPillars() // Get hidden stems and their Ten Gods let hidden = pillars.hiddenTenGods(for: pillars.month.branch) // Main Qi (Stem, TenGods) print("Main Qi: (hidden.benQi.stem.character) [(hidden.benQi.tenGod.name)]") // Middle Qi (Optional<(Stem, TenGods)>) if let zhong = hidden.zhongQi { print("Middle Qi: (zhong.stem.character) [(zhong.tenGod.name)]") } // Residual Qi (Optional<(Stem, TenGods)>) if let yu = hidden.yuQi { print("Residual Qi: (yu.stem.character) [(yu.tenGod.name)]") } ``` -------------------------------- ### Ten Gods Analysis for Stems and Branches in Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Explains how to calculate the Ten Gods (Shi Shen) relationships for Stems and Branches using the SwiftGanZhi library. It covers accessing stem energy and the raw value of stems/branches. ```swift let pillars = date.fourPillars() // Get Ten God for a Stem // Note: Stem/Branch are now wrappers. Property access is transparent. let stemTenGod = pillars.tenGod(for: pillars.year.stem) print(stemTenGod.name) // e.g., "Rob Wealth" // Accessing energy let energy = pillars.month.stem.energy print("Month Stem Energy: (energy)") // In some cases (e.g., matching or strict type passing), use .value for the raw enum let rawStem: Stem = pillars.day.stem.value ``` -------------------------------- ### Detect Stem and Branch Interactions (Swift) Source: https://context7.com/mazeye/swiftstembranch/llms.txt Demonstrates how to automatically detect all Stem and Branch interactions within a BaZi chart, including combinations, clashes, harms, punishments, and destructions. Also shows analysis against dynamic pillars like Grand Luck. Requires the GanZhi library. ```swift import GanZhi let date = Date(year: 1988, month: 6, day: 20, hour: 14, minute: 0)! let pillars = date.fourPillars() // Get all relationships in the chart let relationships = pillars.relationships for rel in relationships { print(rel.description) // e.g., "[Year-Month] 子午地支六冲 Branch Clash" // Structured access let info = rel.listing print("Pillars: (info.pillars)") // "Year-Month" print("Characters: (info.characters)") // "子午" print("Type: (info.type)") // "Branch Clash" } // Analyze relationships between chart and dynamic pillars (Grand Luck/Annual) let grandLuck = StemBranch(stem: .jia, branch: .chen) let yearRels = Relationship.analyze( lhs: pillars.year.value, rhs: grandLuck, lhsName: "Year", rhsName: "Grand Luck" ) for rel in yearRels { print("[(rel.listing.pillars)] (rel.listing.type)") } ``` -------------------------------- ### Create and Navigate Sexagenary Cycle Pairs (Swift) Source: https://context7.com/mazeye/swiftstembranch/llms.txt Demonstrates how to create Stem-Branch pairs directly or from a cycle index, and how to navigate to the next or previous pairs. Requires the GanZhi library. ```swift import GanZhi // Create a Stem-Branch pair directly let jiaZi = StemBranch(stem: .jia, branch: .zi) print(jiaZi.character) // 甲子 print(jiaZi.index) // 0 (first in the 60-year cycle) // Create from cycle index (0-59) let yiChou = StemBranch.from(index: 1) print(yiChou.character) // 乙丑 let guiHai = StemBranch.from(index: 59) print(guiHai.character) // 癸亥 (last in cycle) // Navigate the cycle let next = jiaZi.next // 乙丑 let prev = jiaZi.previous // 癸亥 let skip5 = jiaZi.next(5) // 己巳 ``` -------------------------------- ### Analyze Five Elements System (Swift) Source: https://context7.com/mazeye/swiftstembranch/llms.txt Illustrates how to use the Five Elements enum to check generation and control relationships, and to analyze element distribution and strengths within a BaZi chart. Requires the GanZhi library. ```swift import GanZhi // All five elements let elements = FiveElements.allCases // [.wood, .fire, .earth, .metal, .water] // Get element properties let wood = FiveElements.wood print("Name: (wood.name)") // 木 (or "Wood" in English) // Element relationships (via extension) print(wood.generates(.fire)) // true (Wood generates Fire) print(wood.controls(.earth)) // true (Wood controls Earth) // Get element distribution in a chart let date = Date(year: 2000, month: 1, day: 1, hour: 12, minute: 0)! let pillars = date.fourPillars() let elementCounts = pillars.fiveElementCounts for (element, count) in elementCounts { print("(element.name): (count)") } // Get element energy strengths (weighted) let elementStrengths = pillars.elementStrengths for (element, strength) in elementStrengths { print("(element.name): (String(format: "%.2f", strength))") } ``` -------------------------------- ### Calculate Ten Gods Relationships (Swift) Source: https://context7.com/mazeye/swiftstembranch/llms.txt Shows how to calculate Ten Gods relationships for Stems and Branches relative to the Day Master using the GanZhi library. Supports English language output for Ten God names. ```swift import GanZhi let date = Date(year: 1990, month: 8, day: 15, hour: 12, minute: 0)! let pillars = date.fourPillars() // Get Ten God for any Stem relative to Day Master let yearStemTenGod = pillars.tenGod(for: pillars.year.stem) print("Year Stem Ten God: (yearStemTenGod.name)") // Get Ten God for Branch (uses Main Qi / Ben Qi) let monthBranchTenGod = pillars.tenGod(for: pillars.month.branch) print("Month Branch Ten God: (monthBranchTenGod.name)") // Get detailed Hidden Stems Ten Gods for a Branch let hidden = pillars.hiddenTenGods(for: pillars.day.branch) print("Ben Qi: (hidden.benQi.stem.character) [(hidden.benQi.tenGod.name)]") if let zhong = hidden.zhongQi { print("Zhong Qi: (zhong.stem.character) [(zhong.tenGod.name)]") } if let yu = hidden.yuQi { print("Yu Qi: (yu.stem.character) [(yu.tenGod.name)]") } // Ten God names in English GanZhiConfig.language = .english print(TenGods.sevenKillings.name) // "Seven Killings" print(TenGods.directResource.name) // "Direct Resource" ``` -------------------------------- ### Calculate Ten God and Element Strengths with SwiftGanZhi Source: https://context7.com/mazeye/swiftstembranch/llms.txt Calculates weighted strength values for Ten Gods and Five Elements based on Stems, Hidden Stems, and Branch relationships. Provides distribution percentages for elements and individual pillar energies. Requires the GanZhi library and a Date object. ```swift import GanZhi let date = Date(year: 2000, month: 6, day: 15, hour: 12, minute: 0)! let pillars = date.fourPillars() // Get Ten God strength distribution let tenGodStrengths = pillars.tenGodStrengths for (tenGod, strength) in tenGodStrengths.sorted(by: { $0.value > $1.value }) { if strength > 0 { print("\(tenGod.name): \(String(format: "%.2f", strength))") } } // Get Five Element strength distribution let elementStrengths = pillars.elementStrengths let total = elementStrengths.values.reduce(0, +) for (element, strength) in elementStrengths.sorted(by: { $0.value > $1.value }) { let percentage = (strength / total) * 100 print("\(element.name): \(String(format: "%.2f (%.1f%%)", strength, percentage))") } // Access individual pillar energies print("Day Stem Energy: (pillars.day.stem.energy)") print("Month Branch Energy: (pillars.month.branch.energy)") // Energy calculation factors: // - Seasonal coefficients (Wang Xiang Xiu Qiu Si): 1.4/1.2/1.0/0.8/0.6 // - Rooting strength from Hidden Stems // - Distance decay between pillars // - San He/San Hui relationship bonuses ``` -------------------------------- ### Useful God Analysis in Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Determines the 'Useful God' (Yong Shen) and 'Ji God' (Negative God) using three methods: Pattern, Wang Shuai, and Tiao Hou. The Pattern method is the default. Explicit method selection is supported. Outputs include identified gods and descriptive analysis. ```swift // 1. Default Analysis (Pattern Method) let analysis = pillars.usefulGodAnalysis // 2. Specify Method Explicitly let patternResult = pillars.calculateUsefulGod(method: .pattern) let strengthResult = pillars.calculateUsefulGod(method: .wangShuai) let climateResult = pillars.calculateUsefulGod(method: .tiaoHou) print("--- Pattern Method ---") print("Useful Gods: (patternResult.yongShen.map { $0.name })") print(patternResult.description) print("--- Wang Shuai Method ---") print("Useful Gods: (strengthResult.yongShen.map { $0.name })") print(strengthResult.description) print("--- Climate Method ---") print("status: (climateResult.description)") ``` -------------------------------- ### Relationship Detection (刑冲会合) in SwiftGanZhi Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Demonstrates how to detect various interactions between pillars, including celestial (Stems) and earthly (Branches) relationships like clashes, harmonies, and punishments, using the SwiftGanZhi library. ```swift let relationships = pillars.relationships for rel in relationships { // e.g., "[Year-Month] Zi-Wu Branch Clash" print(rel.description) } // Support detection: // - Stem: Combination (五合), Clash (相冲). // - Branch: Six Harmony (六合), Triple Harmony (三合), Directional (三会), Clash (六冲), Harm (六害), Punishment (相刑), Destruction (相破). ``` -------------------------------- ### Calculate Useful God Analysis with SwiftGanZhi Source: https://context7.com/mazeye/swiftstembranch/llms.txt Determines the Useful God (Yong Shen) and Negative God (Ji Shen) using Pattern, Wang Shuai (Strength), and Tiao Hou (Climate) methods. Requires the GanZhi library and a Date object. Outputs include names of gods, favorable/unfavorable elements, and descriptive reasoning. ```swift import GanZhi let date = Date(year: 1988, month: 8, day: 8, hour: 8, minute: 0)! let pillars = date.fourPillars() // Quick analysis using Pattern method (default) let analysis = pillars.usefulGodAnalysis print("Useful Gods: (analysis.yongShen.map { $0.name }.joined(separator: ", "))") print("Ji Gods: (analysis.jiShen.map { $0.name }.joined(separator: ", "))") print("Favorable Elements: (analysis.favorableElements.map { $0.name })") print("Unfavorable Elements: (analysis.unfavorableElements.map { $0.name })") print("\nReasoning:\n(analysis.description)") // Analyze with specific methods let patternResult = pillars.calculateUsefulGod(method: .pattern) let strengthResult = pillars.calculateUsefulGod(method: .wangShuai) let climateResult = pillars.calculateUsefulGod(method: .tiaoHou) print("--- Pattern Method ---") print("Useful: (patternResult.yongShen.map { $0.name })") print("--- Wang Shuai Method ---") print("Useful: (strengthResult.yongShen.map { $0.name })") print("--- Climate Method ---") print("Analysis: (climateResult.description)") // Methods explained: // .pattern - Traditional pattern-based analysis // .wangShuai - Strength/weakness balance analysis // .tiaoHou - Temperature/moisture climate adjustment ``` -------------------------------- ### Analyze Branch-based Shen Sha Stars - Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Analyzes common Shen Sha (stars/gods) based on Life Stages and Five Elements relationships within specific branches of a pillar. It retrieves the stars associated with a given branch and prints their names if any are found. ```swift let branch = pillars.month.branch let stars = pillars.shenSha(for: branch) if !stars.isEmpty { // Use .name for localized output print("Stars: (stars.map { $0.name }.joined(separator: " "))") // e.g., "Stars: Nobleman Traveling Horse" } ``` -------------------------------- ### Analyze Thermal Balance (Temperature and Moisture) with Swift Source: https://context7.com/mazeye/swiftstembranch/llms.txt Analyzes the thermal (Han Nuan) and moisture (Shi Zao) balance of a BaZi chart. It considers the positions of Fire/Water elements and Life Stages to determine the chart's temperature and moisture levels and identify special states like 'Frozen' or 'Vapor'. ```swift import GanZhi let date = Date(year: 1995, month: 12, day: 15, hour: 3, minute: 0)! let pillars = date.fourPillars() // Get thermal balance analysis let tb = pillars.thermalBalance print(String(format: "Temperature: %.2f", tb.temperature)) print(String(format: "Moisture: %.2f", tb.moisture)) // Check special states if tb.isFrozen { print("Status: Frozen (Temperature <= 0)") print("Chart needs warmth (Fire element)") } else if tb.isVapor { print("Status: Vapor (Temperature > 100)") print("Chart has excessive fire") } else { print("Status: Normal temperature range") } // Temperature is influenced by: // - Month Branch baseline temperature // - Fire stems (Bing/Ding) with Life Stage coefficients // - Hidden fire in branches // Moisture is influenced by: // - Water stems (Ren/Gui) // - Earth stems (Wu/Ji - dry/wet) // - Hidden water and earth in branches ``` -------------------------------- ### Calculate Shen Sha Stars and Global Situations with Swift Source: https://context7.com/mazeye/swiftstembranch/llms.txt Calculates auspicious and inauspicious stars (Shen Sha) for specific branches within a BaZi chart and detects chart-wide Global Situations. It also allows for registering custom Global Situation rules. ```swift import GanZhi let date = Date(year: 1992, month: 3, day: 15, hour: 9, minute: 0)! let pillars = date.fourPillars() // Get Shen Sha for a specific branch let monthStars = pillars.shenSha(for: pillars.month.branch) for star in monthStars { print(star.name) // e.g., "Nobleman", "Traveling Horse" } // Available Shen Sha include: // Noblemen: tianYi, taiJi, wenChang, tianDe, yueDe // Character: yiMa, taoHua, huaGai, jiangXing, jinShen // Wealth/Power: luShen, jinYu // Inauspicious: yangRen, feiRen, kongWang, yuanChen, etc. // Get all Global Situations (chart-wide patterns) let globalSituations = pillars.allGlobalSituations print("Global Situations: (globalSituations.joined(separator: ", "))") // Register custom Global Situation rule GlobalSituationRegistry.register("Pure Yang") { chart in let stems = [chart.year.stem, chart.month.stem, chart.day.stem, chart.hour.stem] let branches = [chart.year.branch, chart.month.branch, chart.day.branch, chart.hour.branch] return stems.allSatisfy { $0.yinYang == .yang } && branches.allSatisfy { $0.yinYang == .yang } } // Custom rules are automatically checked let updatedSituations = pillars.allGlobalSituations ``` -------------------------------- ### Configure Geographic Location for Solar Time in Swift Source: https://context7.com/mazeye/swiftstembranch/llms.txt The `Location` struct allows configuration of geographic coordinates (longitude and timezone) for accurate True Solar Time calculations. This is crucial for precise hour pillar determination based on the sun's actual position. ```swift import GanZhi // Create a location with longitude and timezone let tokyo = Location(longitude: 139.7, timeZone: 9.0) let newYork = Location(longitude: -74.0, timeZone: -5.0) // Built-in Beijing location let beijing = Location.beijing // longitude: 120.0, timeZone: 8.0 // Use location for Four Pillars calculation let birthDate = Date(year: 1990, month: 6, day: 15, hour: 10, minute: 30)! let pillars = birthDate.fourPillars(at: tokyo) // The hour pillar is now adjusted based on Tokyo's longitude // relative to the JST timezone standard meridian (135 deg E) print("Corrected Hour: \(pillars.hour.character)") ``` -------------------------------- ### Determine Chart Pattern - Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Automatically determines the chart pattern based on traditional rules like Month Qi priority and Stem penetration. It also includes logic for auxiliary pattern detection in Peer-type charts, ensuring the auxiliary dominates the 'Self Group' for increased rigor. Outputs include the pattern description, the basis for determination, and the core 'Ten God'. ```swift let pattern = pillars.determinePattern() print("Pattern: (pattern.description)") // e.g., "Direct Resource Pattern" print("Basis: (pattern.method.description)") // e.g., "Month Branch Main Qi" print("Core Ten God: (pattern.tenGod.name)") // e.g., "Direct Resource" ``` -------------------------------- ### Configure Internationalization for GanZhi Output Source: https://context7.com/mazeye/swiftstembranch/llms.txt Sets the output language for localized text within the GanZhi library, including Stems, Branches, Ten Gods, Patterns, and Shen Sha names. Supports Simplified Chinese, English, Traditional Chinese, and Japanese. Requires the GanZhi library. ```swift import GanZhi // Default is Simplified Chinese print(Stem.jia.character) // 甲 print(TenGods.friend.name) // 比肩 // Switch to English GanZhiConfig.language = .english print(Stem.jia.character) // Jia print(TenGods.friend.name) // Friend print(Branch.zi.character) // Zi print(FiveElements.wood.name) // Wood // Traditional Chinese GanZhiConfig.language = .traditionalChinese print(TenGods.robWealth.name) // 劫財 // Japanese GanZhiConfig.language = .japanese print(TenGods.sevenKillings.name) // 偏官 print(ShenSha.taoHua.name) // 咸池 // Reset to default GanZhiConfig.language = .simplifiedChinese ``` -------------------------------- ### Determine BaZi Chart Pattern with Swift Source: https://context7.com/mazeye/swiftstembranch/llms.txt Analyzes the BaZi chart structure to identify the traditional pattern based on Month Qi priority and Stem penetration. It returns the primary pattern, its determining method, and the core Ten God, with optional auxiliary patterns. ```swift import GanZhi let date = Date(year: 1985, month: 10, day: 25, hour: 8, minute: 0)! let pillars = date.fourPillars() // Determine the chart pattern let pattern = pillars.determinePattern() print("Pattern: (pattern.description)") // e.g., "Direct Resource Pattern" print("Method: (pattern.method.description)") // e.g., "Month Branch Main Qi" print("Core Ten God: (pattern.tenGod.name)") // e.g., "Direct Resource" // Check for auxiliary patterns if let aux = pattern.auxiliaryTenGod { print("Auxiliary: (aux.name)") print("Auxiliary Method: (pattern.auxiliaryMethod?.description ?? "")") } // Pattern types include: // - Standard: Direct Officer, Seven Killings, Direct Wealth, etc. // - Peer: Jian Lu (建禄格), Yang Ren (羊刃格), Yue Ren (月刃格) // - Special: Follow patterns (从杀格, 从财格, 从儿格) // - Vitalized: Qu Zhi, Yan Shang, Jia Se, Cong Ge, Run Xia ``` -------------------------------- ### Dynamic Relationship Analysis in Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Analyzes relationships between any two Stem-Branch pairs, such as comparing a Chart against Dynamic Pillars (e.g., Grand Luck, Annual Luck). Supports detection of Duplicates (Fu Yin), Clashes (Fan Yin), and standard relationships like Combinations, Clashes, Harm, Punishment, and Destruction. Results can be accessed via direct description or structured information. ```swift // 1. Create a Chart let chart = FourPillars(date: Date()) // 2. Define a Dynamic Pillar (e.g., Grand Luck "Jia-Chen") let grandLuck = StemBranch(stem: .jia, branch: .chen) // 3. Analyze Relationships (e.g., Year Pillar vs. Grand Luck) let yearRels = Relationship.analyze( lhs: chart.year.value, rhs: grandLuck, lhsName: "Year", rhsName: "Grand Luck" ) // Print results for rel in yearRels { // Method 1: Direct Description (Old Way) // print(rel.description) // [Year-Grand Luck] 辰酉地支六合 Branch Six Harmony // Method 2: Structured Access (New Way) let info = rel.listing print("Pillars: (info.pillars)") // "Year-Grand Luck" print("Characters: (info.characters)") // "ChenYou" print("Type: (info.type)") // "Branch Six Harmony" } ``` -------------------------------- ### Calculate Four Pillars using Swift Date Extension Source: https://context7.com/mazeye/swiftstembranch/llms.txt Extends Swift's Date type to calculate BaZi Four Pillars. Supports Mean Solar Time (default) and True Solar Time with optional geographic location correction for accurate hour pillar determination. ```swift import GanZhi // Create a date using the convenient initializer let date = Date(year: 2024, month: 2, day: 4, hour: 16, minute: 30)! // Calculate Four Pillars using Mean Solar Time (default) let pillars = date.fourPillars() print(pillars.description) // Output: 甲辰年 丙寅月 戊戌日 庚申时 // Access individual pillars print("Year: \(pillars.year.character)") // 甲辰 print("Month: \(pillars.month.character)") // 丙寅 print("Day: \(pillars.day.character)") // 戊戌 print("Hour: \(pillars.hour.character)") // 庚申 // Access Stem and Branch separately print("Day Stem: \(pillars.day.stem.character)") // 戊 print("Day Branch: \(pillars.day.branch.character)") // 戌 // Calculate with True Solar Time for a specific location let urumqi = Location(longitude: 87.6, timeZone: 8.0) let correctedPillars = date.fourPillars(at: urumqi) print("Hour Branch (Corrected): \(correctedPillars.hour.branch.character)") // Original 10:00 Beijing time becomes ~07:50 local solar time ``` -------------------------------- ### Analyze Global Situations (Chart-wide Patterns) - Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Analyzes patterns that apply to the entire astrological chart or specific pillar combinations, such as San Qi and Kui Gang. It retrieves all global situations detected in the chart and prints them as a space-separated string. Built-in support includes Three Wonders, Kui Gang, Golden Spirit, Ten Evils Big Failure, and Heavenly Unity. ```swift let globalSituations = pillars.allGlobalSituations if !globalSituations.isEmpty { print("Global Situations: (globalSituations.joined(separator: " "))") // e.g., "Global Situations: Three Wonders Kui Gang Nobleman" } ``` -------------------------------- ### Analyze Thermal Balance (Temperature & Moisture) - Swift Source: https://github.com/mazeye/swiftstembranch/blob/main/README.md Analyzes the 'Han Nuan Zao Shi' (Cold/Warm/Dry/Wet) balance of an astrological chart. Temperature is calculated based on Fire element strength, and Moisture based on Water and Earth content. The code prints the calculated temperature and moisture values, and also checks for 'Frozen' (Temp ≤ 0) and 'Vapor' (Temp > 100) states. ```swift let tb = pillars.thermalBalance print(String(format: "Temperature: %.2f", tb.temperature)) print(String(format: "Moisture: %.2f", tb.moisture)) if tb.isFrozen { print("Status: Frozen") } else if tb.isVapor { print("Status: Vapor") } ``` -------------------------------- ### Swift Stem Enum: Properties and Navigation Source: https://context7.com/mazeye/swiftstembranch/llms.txt The `Stem` enum in SwiftGanZhi represents the Ten Heavenly Stems. It provides properties for Five Elements, Yin/Yang polarity, character representation, and allows for cyclical navigation (next/previous stem). ```swift import GanZhi // Access all stems let allStems = Stem.allCases // [.jia, .yi, .bing, .ding, .wu, .ji, .geng, .xin, .ren, .gui] // Get stem properties let stem = Stem.jia print("Character: \(stem.character)") // 甲 print("Five Element: \(stem.fiveElement)") // .wood print("Yin/Yang: \(stem.yinYang)") // .yang // Stem cycle navigation let nextStem = stem.next(1) // .yi let prevStem = stem.previous(1) // .gui (wraps around) // Configure English output GanZhiConfig.language = .english print(Stem.bing.character) // "Bing" ``` -------------------------------- ### Swift Branch Enum: Properties and Hidden Stems Source: https://context7.com/mazeye/swiftstembranch/llms.txt The `Branch` enum represents the Twelve Earthly Branches in SwiftGanZhi. It includes properties for character, Five Elements, Yin/Yang polarity, and detailed information about Hidden Stems (Cang Gan), including Main, Middle, and Residual Qi. ```swift import GanZhi // Access all branches let allBranches = Branch.allCases // [.zi, .chou, .yin, .mao, .chen, .si, .wu, .wei, .shen, .you, .xu, .hai] // Get branch properties let branch = Branch.yin // Tiger print("Character: \(branch.character)") // 寅 print("Five Element: \(branch.fiveElement)") // .wood print("Yin/Yang: \(branch.yinYang)") // .yang // Hidden Stems (Cang Gan) print("All Hidden: \(branch.hiddenStems.map { $0.character })") // ["甲", "丙", "戊"] print("Ben Qi (Main): \(branch.benQi.character)") // 甲 print("Zhong Qi (Middle): \(branch.zhongQi?.character ?? "none")") // 丙 print("Yu Qi (Residual): \(branch.yuQi?.character ?? "none")") // 戊 // Branch cycle navigation let nextBranch = branch.next(6) // .shen (Monkey) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.